ComfortablyNumb
asked on
TSQL Delete with Referential Integrity
Hi Experts,
I need to clear out some tables from a SQL 2008 database that are all nicely referenced to one another.
Is there a script that can delete/truncate a table and reseed it regardless of whether it is referenced or not?
Cheers,
Numb
I need to clear out some tables from a SQL 2008 database that are all nicely referenced to one another.
Is there a script that can delete/truncate a table and reseed it regardless of whether it is referenced or not?
Cheers,
Numb
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
If you wanted to write a script for it just start at the bottom table (eg: the table that references nothing) and work your way up.
The other thing you can do is drop the foreign keys but I would not recommend doing that, as you will break the relationships and have dirty data. Regardless of what you do, make a backup of the database first!