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 2000 Forums
 SQL Server Development (2000)
 Copy records and related records changing PKs, FKs

Author  Topic 

traigo
Starting Member

4 Posts

Posted - 2010-04-29 : 15:52:35
I have a large group of tables with related PKs and FKs but it's not a simple copy all and change the FK to the new PK.
Employees,Departments,Locations, etc have FK to Company PK
EmployeeDepartments,EmployeeLocations have FK to Employee and FK to Departments,Locations

This is a small set of the ~80 tables that are linked in some way. Is there an easy way, in SQL or T-SQL, to copy all the information and assign new PKs and update the new FKs? I'd prefer not to have to manually code a function to do this as tables add/change frequently with development progressing (I'd have to keep updating it to keep up with table changes).

Thanks,
Traigo
   

- Advertisement -