all groups > sql server (alternate) > july 2007 >
You're in the

sql server (alternate)

group:

Deleting all data


Deleting all data Tmuld
7/26/2007 12:01:36 PM
sql server (alternate): Is there a way to delete all data from a database - all tables and all
tables excluding system tables?

sqlserver 2000?

Thanks,

Tmuld
Re: Deleting all data Erland Sommarskog
7/26/2007 9:37:08 PM
Tmuld (tmuldoon@spliced.com) writes:
[quoted text, click to view]

A brute force method is to run

SELECT 'DELETE ' + name FROM sysobjects WHERE type = 'U'

Copy and paste the result into a query window, and the run it over and
over again, until there are no error messages. This presumes that the
only errors you get are from foreign keys. If you have triggers that
object to the deletion, you need to disable these.

Another alternative is build an empty database from scripts, either
taken from version control or generated by Enterprise Manager.


--
Erland Sommarskog, SQL Server MVP, esquel@sommarskog.se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/prodtechnol/sql/2005/downloads/books.mspx
Books Online for SQL Server 2000 at
Re: Deleting all data Hugo Kornelis
7/26/2007 11:56:42 PM
[quoted text, click to view]

Hi Tmuld,

DROP DATABASE xxx
go
CREATE DATABASE xxx
-- add options here
go

--
Hugo Kornelis, SQL Server MVP
AddThis Social Bookmark Button