You are here: Re: Deleting all data « MsSQL Server « IT news, forums, messages
Re: Deleting all data

Posted by Erland Sommarskog on 07/26/07 21:37

Tmuld (tmuldoon@spliced.com) 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@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
http://www.microsoft.com/sql/prodinfo/previousversions/books.mspx

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация