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
 SQL Server Development (2000)
 Deleting all the tables in a DB.

Author  Topic 

ravilobo
Master Smack Fu Yak Hacker

1184 Posts

Posted - 2002-09-21 : 07:29:05
I have a requirement where in i need to truncate the tables in a DB regularly. I have more than 200 tables, with relationships.

I need to delete the child tables first, followed by master tables.
Its difficult to search for master tables out of 200 tables.

Is there any easier way to do this?

Alternate method is, delete the DB, create new one and run the db script. Since this activity is going to happen on a production server, i think this deleting and recreating will lead to fragmentation of the hard disk.

Is there any easier solution to this?

Thanks in advance..



robvolk
Most Valuable Yak

15732 Posts

Posted - 2002-09-21 : 09:42:06
If you're using SQL Server 2000, you can create FOREIGN KEY constraints between parent and child tables and specify ON DELETE CASCADE. This will allow you to delete rows from the parent table, and all related rows in the child tables will delete automatically.

If you're using SQL 7.0, then this procedure will allow you the same functionality:

http://www.sqlteam.com/item.asp?ItemID=8595

Go to Top of Page
   

- Advertisement -