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
ComfortablyNumbAsked:
Who is Participating?
 
JaseemKConnect With a Mentor Commented:
Hi there. Please refer to the following article for your possible solution:

http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=65341

HTH.
0
 
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!
0
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.