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
 Old Forums
 CLOSED - General SQL Server
 How To Delete All Tables

Author  Topic 

kjmraohyd
Starting Member

34 Posts

Posted - 2006-06-27 : 08:30:13
Ihave the following statement deletes all the rows but I get FK violations for some ogf the Tables.

select 'delete from '+name from sysobjects where type='u'

How to take care of the delete from child first and then parent?

Jagan

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2006-06-27 : 08:42:53
Instead of Delete, truncate them
Refer this
http://sqlteam.com/forums/topic.asp?TOPIC_ID=65341

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2006-06-27 : 13:40:19
I thought you couldn't truncat tables with RI



Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Add yourself!
http://www.frappr.com/sqlteam
Go to Top of Page

rockmoose
SQL Natt Alfen

3279 Posts

Posted - 2006-06-27 : 13:55:08
" I thought you couldn't truncat tables with RI"
Nope you can't, have to delete.
Ever run a delete script until there were no more errors?
Go to Top of Page

DonAtWork
Master Smack Fu Yak Hacker

2167 Posts

Posted - 2006-06-27 : 14:31:46
hmmm. the topic was "How to delete all tables"

Does this not meet the requirements?

USE MASTER
DROP DATABASE [your database here]


EDIT: Someone posted an AWESOME script a while back that scripted out all constraints, and removed them in the right order, THEN put them back, in the right order. I will dig around and see if i can find a link to it.
Help us help YOU!
Read this blog entry for more details: http://weblogs.sqlteam.com/brettk/archive/2005/05/25.aspx

*need more coffee*
SELECT * FROM Users WHERE CLUE > 0
(0 row(s) affected)
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2006-06-28 : 02:13:18
quote:
Originally posted by X002548

I thought you couldn't truncat tables with RI



Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Add yourself!
http://www.frappr.com/sqlteam



Yes. Look at the script I posted. It deletes all parent tables after truncating Child tables

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -