Re: Deleting all data



Tmuld (tmuldoon@xxxxxxxxxxx) writes:
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@xxxxxxxxxxxxx

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
http://www.microsoft.com/sql/prodinfo/previousversions/books.mspx
.



Relevant Pages

  • Re: ExecutionEngineException in Sql 2005 management studio
    ... The query window ... Here's a stack dump, ... Erland Sommarskog, SQL Server MVP, esquel@xxxxxxxxxxxxx ... Books Online for SQL Server 2005 at ...
    (microsoft.public.sqlserver.tools)
  • Re: SQLCMD "-r" option (SQL 2K5)
    ... so that output would be sent to a file and error messages ... The error message is sent to the output file and not to the ... Erland Sommarskog, SQL Server MVP, esquel@xxxxxxxxxxxxx ... Books Online for SQL Server 2005 at ...
    (microsoft.public.sqlserver.tools)
  • Re: T-SQL Debugger Doesnt Allow Stepping Through Stored Procedures no other procedure with the s
    ... There is no error messages also, ... the debugger to work. ... SQL Server does not have privilege to write to your machine from ... In Books Online, you can look under Troubleshooting->SQL Server Tools ...
    (comp.databases.ms-sqlserver)
  • Re: DBPROB for Session timeout
    ... Which one of these values sets the timeout for a SQLServer-Session? ... Microsoft OLE DB Provider for SQL Server ... installed, you can test this by open a query window, put the computer ... Books Online for SQL Server 2005 at ...
    (microsoft.public.data.oledb)
  • Re: xml viewer
    ... I get the xml viewable link ... If I open a New Query window and do ... Erland Sommarskog, SQL Server MVP, esquel@xxxxxxxxxxxxx ... Books Online for SQL Server 2005 at ...
    (microsoft.public.sqlserver.tools)