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
 SQL Server 2000 Forums
 Transact-SQL (2000)
 How to delete all records from all tables of the d

Author  Topic 

kamii47
Constraint Violating Yak Guru

353 Posts

Posted - 2006-03-29 : 04:19:17
I want's to find out query for "How to delete all records from all tables of the database" without disturbing structure

RickD
Slow But Sure Yak Herding Master

3608 Posts

Posted - 2006-03-29 : 05:11:44
Look up the information_schema in BOL.. That'll start you off..
Go to Top of Page

chiragkhabaria
Master Smack Fu Yak Hacker

1907 Posts

Posted - 2006-03-29 : 05:35:19
for getting list of all the tables you will get from
Information_Schema.Tables

Then using cursors you need to write the dynamic query to delete records from all the tables..



If Debugging is the process of removing Bugs then i Guess programming should be process of Adding them.
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2006-03-29 : 05:42:30
Instead of deleting tables, truncate them
http://www.extremeexperts.com/SQL/Scripts/TruncateAllTables.aspx

Madhivanan

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

kamii47
Constraint Violating Yak Guru

353 Posts

Posted - 2006-03-30 : 01:22:02
What about if i have refrential integrity in the tables ??????
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2006-03-30 : 03:15:06
You need to truncate all child tables before Parent table

Madhivanan

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

mr_mist
Grunnio

1870 Posts

Posted - 2006-03-30 : 03:18:14
Drop the referential integrity constraints, truncate the tables, re-establish the constraints.

Otherwise you will likely have to code your solution manually, because a simple script that uses the system tables or ms_foreachtable won't be able to account for the ordering you'll need to delete the right entries first.

Why are you having to do this? You may as well drop the database and recreate it with your table creation scripts (Script them from EM if you haven't got such things.)

-------
Moo. :)
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2007-11-27 : 07:37:33
quote:
Originally posted by kamii47

I want's to find out query for "How to delete all records from all tables of the database" without disturbing structure


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

Madhivanan

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

- Advertisement -