0

I have db in SQL Server 2008 R2.

I have table Users and some child tables that have foreign key relationships to UserID.

I forgot to add on cascade delete and update in the creation.

There is a way to do it now, without losing the data?

Thanks !

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
user2097810
  • 735
  • 6
  • 17
  • 25

1 Answers1

1

You have to drop the key and re-add it like this:

ALTER TABLE someTable DROP FOREIGN KEY someID;
ALTER TABLE someTable ADD FOREIGN KEY (someID) REFERENCES someOtherTable (ID) ON DELETE CASCADE;

I hope this helps.

Outsider
  • 550
  • 3
  • 9