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
 General SQL Server Forums
 New to SQL Server Programming
 On Update Cascade ...

Author  Topic 

shapper
Constraint Violating Yak Guru

450 Posts

Posted - 2009-08-06 : 17:45:45
Hello,

I understand how On Delete Cascade works.
If a record R1 on table A is deleted all records related to R1 on table B are deleted.
(This considering tables A and B are related).

What I don't understand is the On Update Cascade.
If I update only the record R1 in A nothing changes in B ... unless I change the ID of R1 in A.
But usually that doesn't happen. Why would I change the ID?

Could someone, please clarify me on this?

Thanks,
Miguel

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2009-08-06 : 18:04:01
This is because the foreign key constraint is on the ID column, so only the ID is cascaded.

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

Subscribe to my blog

"Let's begin with the premise that everything you've done up until this point is wrong."
Go to Top of Page

shapper
Constraint Violating Yak Guru

450 Posts

Posted - 2009-08-06 : 18:09:21
But is there a situation where the update cascade would have more then the ID just to understand.

Thanks,
Miguel
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2009-08-06 : 18:13:12
It depends on what you put in the foreign key constraint. Whatever is in the FK is what will be cascaded. If you want other columns to be cascaded, then you may want to use triggers instead or better yet normalize your database.

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

Subscribe to my blog

"Let's begin with the premise that everything you've done up until this point is wrong."
Go to Top of Page
   

- Advertisement -