Thursday, March 8, 2012

Cascade Update

Does anyone know how to do a cascade update in SQL 2005 using the studio manager?

Basically, I have a project table with a status column. If the status is set to 2, then I need to update another table that references the project id.

You can create a foreign key with cascading. For example you have 2 tables: the referenced table tbl1 with projectid as primary key, and the referencing table tbl2 with projectid column:

Alter Table tbl2 Add
Constraint fk_tbl2_projectid
Foreign Key (projectid)
References tbl1(projectid)
On Update Cascade

You can get more information from these links:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/tsqlref/ts_aa-az_3ied.asp

And

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/createdb/cm_8_des_04_92ib.asp

No comments:

Post a Comment