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?

Who is Participating?
JaseemKConnect With a Mentor Commented:
Hi there. Please refer to the following article for your possible solution:


Kyle AbrahamsSenior .Net DeveloperCommented:
That's the point of a reference . . . so that you don't break parent child relationships.

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!
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.