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.
| Author |
Topic |
|
rudesyle
Posting Yak Master
110 Posts |
Posted - 2007-11-28 : 09:26:07
|
| Hi All,I have a table that uses two columns for it's primary key. That key is then used as a fk constraint of a number of other tables. I now have a request to update one of the key values in the Parent table. Doing so, of course, violates the fk constraint. My first thought was to disable the constraint, do the updates, and then enable the constraint. But after some thought, I decided this is not a good idea. The only other was I can think of doing this is to :(1)insert data from child tables into a temp table(2)delete data from child tables(3)Update parent data with new column value(4)Update temp tables with new column value(5)Insert temp data back into child tablesCan anyone else think of an easier way? |
|
|
suresha_b
Yak Posting Veteran
82 Posts |
Posted - 2007-11-28 : 10:00:04
|
| 1) Insert a new row to the parent table with new values.2) Update the child tables3) Delete the old row from the parent table.Suresh B. |
 |
|
|
rudesyle
Posting Yak Master
110 Posts |
Posted - 2007-11-28 : 10:18:18
|
quote: Originally posted by suresha_b 1) Insert a new row to the parent table with new values.2) Update the child tables3) Delete the old row from the parent table.Suresh B.
Thanks Suresh. Nice simple solution! |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2007-11-28 : 10:34:01
|
| Just to confirm, wont this be automatically done by SQl Server if we've specified ON UPDATE CASCADE option with fk constraint? |
 |
|
|
|
|
|