I\'d like to clear the database altogether and reset the data. What\'s the quickest way to do that? Or, what\'s the command that will delete all the rows of a table (and I\'
This approach will enable you to delete content from all tables, even those referenced by a foreign key constraint. You can enhance it to make it check for the absence of foreign key constraints and do a TRUNCATE TABLE
in those cases.
EXEC sp_msforeachtable 'ALTER TABLE ? NOCHECK CONSTRAINT ALL'
EXEC sp_msforeachtable 'DELETE FROM ?'
EXEC sp_msforeachtable 'ALTER TABLE ? WITH CHECK CHECK CONSTRAINT ALL'
Use SQL Server Management Studio to script the DROP and CREATE statements for the tables and then run the script. Right click on the database and select Tasks --> Generate Scripts. Run through the wizard (make sure to check the Script Drop option on the "Choose Script Options" step) and select all of the tables. The script that is generated should drop all the tables and then recreate them.
If you don't want to script and drop the tables, there are a number of ways to do this with a loop. Here's probably the easiest:
sp_MsForEachTable 'TRUNCATE TABLE ?'
Drop the database and recreate it.