Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2008 Forums
 Other SQL Server 2008 Topics
 update trigger

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 change
primary idst
foreign 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 MVP
http://visakhm.blogspot.com/

Go to Top of Page

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?
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2012-01-26 : 17:05:45
quote:
Originally posted by saman.m

thanks ,But I want to know how to do this with a trigger



Why? While we are here to answer questions, we also are here to make sure people don't go down the wrong path.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2012-01-26 : 17:13:42
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?



Yes it's possible, not recommended, but possible.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

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 MVP
http://visakhm.blogspot.com/

Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2012-01-26 : 18:20:38
Either that or homework as it just doesn't make sense to be dead set on using a trigger here.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2012-01-27 : 11:04:45
...never mind that "changing" keys is just a plain bad idea



Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx


Want to help yourself?

http://msdn.microsoft.com/en-us/library/ms130214.aspx

http://weblogs.sqlteam.com/brettk/

http://brettkaiser.blogspot.com/


Go to Top of Page

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 Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page
   

- Advertisement -