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 2005 Forums
 Transact-SQL (2005)
 Change PrimaryK &ForeignK value simultaneously

Author  Topic 

K_P
Starting Member

10 Posts

Posted - 2008-04-04 : 14:42:50
Hi, can anyone help me with this? I need to write a proc to update all the tables in database with EmpNo where Employee is the master(Parent-table).

snSQL
Master Smack Fu Yak Hacker

1837 Posts

Posted - 2008-04-05 : 00:30:11
You need to first disable the foreign key constraint like this
ALTER TABLE MyTable NOCHECK CONSTRAINT MyConstraint

Now change the primary key value/s.
Then change the foreign key value/s.
And finally re-enable the foreign key constraint with
ALTER TABLE MyTable CHECK CONSTRAINT MyConstraint

Go to Top of Page
   

- Advertisement -