Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

TSQL Delete with Referential Integrity

Posted on 2011-05-12
2
Medium Priority
?
437 Views
Last Modified: 2012-05-11
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
0
Comment
Question by:ComfortablyNumb
2 Comments
 
LVL 3

Accepted Solution

by:
JaseemK earned 2000 total points
ID: 35746635
Hi there. Please refer to the following article for your possible solution:

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

HTH.
0
 
LVL 41

Expert Comment

by:Kyle Abrahams
ID: 35746651
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

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In part one, we reviewed the prerequisites required for installing SQL Server vNext. In this part we will explore how to install Microsoft's SQL Server on Ubuntu 16.04.
One of the most important things in an application is the query performance. This article intends to give you good tips to improve the performance of your queries.
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question