Author |
Topic |
saman.m
Starting Member
2 Posts |
Posted - 2012-01-26 : 10:01:23
|
hi I have 2 tables I write update trigger on the table when the table st primary key was changed ,the foreign key for the table is dependent on the changeprimary idstforeign stid |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2012-01-26 : 10:46:45
|
you dont need a trigger for that if you want it to be reflected automatically. You just need to modify foreign key constraint to enable the ON UPDATE CASCADE option------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
|
|
saman.m
Starting Member
2 Posts |
Posted - 2012-01-26 : 17:04:20
|
thanks ,But I want to know how to do this with a trigger? Whether it is possible to trigger? |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2012-01-26 : 18:16:26
|
quote: Originally posted by saman.m thanks ,But I want to know how to do this with a trigger? Whether it is possible to trigger?
is it an iterview question? ------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
X002548
Not Just a Number
15586 Posts |
|
tkizer
Almighty SQL Goddess
38200 Posts |
Posted - 2012-01-27 : 12:34:47
|
quote: Originally posted by X002548 ...never mind that "changing" keys is just a plain bad idea
In agreement 100%! I have an app that does this. It's the most critical app that we have. Several updates are done per day on the table that allows this. Let's just say it creates a massive performance issue each time someone updates the PK because that column is in indexes and foreign keys EVERYWHERE in that database.Tara KizerMicrosoft MVP for Windows Server System - SQL Serverhttp://weblogs.sqlteam.com/tarad/Subscribe to my blog |
|
|
|