dbTalk Databases Forums  

Deleting all data

comp.databases.ms-sqlserver comp.databases.ms-sqlserver


Discuss Deleting all data in the comp.databases.ms-sqlserver forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Tmuld
 
Posts: n/a

Default Deleting all data - 07-26-2007 , 02:01 PM






Is there a way to delete all data from a database - all tables and all
tables excluding system tables?

sqlserver 2000?

Thanks,

Tmuld


Reply With Quote
  #2  
Old   
Erland Sommarskog
 
Posts: n/a

Default Re: Deleting all data - 07-26-2007 , 04:37 PM






Tmuld (tmuldoon (AT) spliced (DOT) com) writes:
Quote:
Is there a way to delete all data from a database - all tables and all
tables excluding system tables?
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 (AT) sommarskog (DOT) se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pro...ads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinf...ons/books.mspx


Reply With Quote
  #3  
Old   
Hugo Kornelis
 
Posts: n/a

Default Re: Deleting all data - 07-26-2007 , 04:56 PM



On Thu, 26 Jul 2007 12:01:36 -0700, Tmuld wrote:

Quote:
Is there a way to delete all data from a database - all tables and all
tables excluding system tables?

sqlserver 2000?
Hi Tmuld,

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

--
Hugo Kornelis, SQL Server MVP
My SQL Server blog: http://sqlblog.com/blogs/hugo_kornelis


Reply With Quote
  #4  
Old   
Joe Hurzeler
 
Posts: n/a

Default Re: Deleting all data - 10-24-2007 , 08:02 PM



Hugo Kornelis <hugo (AT) perFact (DOT) REMOVETHIS.info.INVALID> wrote in
news36ia39c3bhvcs5dfjsbluvphgus0nbqtu (AT) 4ax (DOT) com:

Quote:
On Thu, 26 Jul 2007 12:01:36 -0700, Tmuld wrote:

Is there a way to delete all data from a database - all tables and all
tables excluding system tables?

sqlserver 2000?

Hi Tmuld,

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

Might not be a bad idea to create a script to recreate the database and all
its objects before you start if you don't want to reinvent the wheel.


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.