I have a lot of Foreign Key Columns with cascade delete set to NO ACTION in some specific Schema and I want to Set the FK Columns to ON DELETE SET NULL (for Example) where Primary Key Column's Schema relating to this Foreign Key Column is starting with 'Store'. I found this article in stack overflow SQL Script to alter ALL Foreign Keys to add ON DELETE CASCADE but unfortunately I was unable to edit it to fit my needs, can somebody help...
Asked
Active
Viewed 56 times
0
-
"unable to edit it to fit my needs" why? Please explain. It seems like you just need to add `where ForeignTableSchema = 'Store'` – Charlieface Jul 28 '22 at 09:09
-
Sorry @Charlieface I forgot something important in the question and i edited it please re-read it again, and if you didn't understand reply.. – Meshka Jul 28 '22 at 09:19
-
`where schema_name(sys.objects.schema_id) = 'STORE'` although I must say that that script could do with improvement – Charlieface Jul 28 '22 at 09:22
-
@Charlieface Is this schema for PRIMARY KEY Column? – Meshka Jul 28 '22 at 09:25
-
Yes, have you tried it? Read the code in that link and understand what it does. – Charlieface Jul 28 '22 at 16:27
-
@Charlieface didn't work at all...!!! – Meshka Jul 28 '22 at 17:06
-
Without seeing what you tried we cannot help – Charlieface Jul 29 '22 at 10:14