Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>There are a few options you could take, the "fastest" really depends on your database.</p> <p>To firstly answer your questions on seeding, etc - TRUNCATE TABLE will delete all information in a table (very fast, as it is not logged) and will reset your identity column.</p> <p>eg:</p> <pre><code>TRUNCATE TABLE dbo.table </code></pre> <p><a href="http://msdn.microsoft.com/en-us/library/aa260621(SQL.80).aspx" rel="nofollow noreferrer">http://msdn.microsoft.com/en-us/library/aa260621(SQL.80).aspx</a></p> <p>The significant restriction here is that you cannot use it on a table that is referenced by another table. In this case you can use a standard delete and then use DBCC CHECKIDENT</p> <p>eg:</p> <pre><code>DELETE FROM dbo.table GO DBCC CHECKIDENT(dbo.table, reseed, 0) </code></pre> <p><a href="http://msdn.microsoft.com/en-us/library/ms176057.aspx" rel="nofollow noreferrer">http://msdn.microsoft.com/en-us/library/ms176057.aspx</a></p> <p>Remember with delete to make sure you delete information in the correct order (i.e. taking into account foreign keys).</p> <p>Another approach I often use is simply writing a complete tear-down / rebuild script when I want to reset the database. The basic premise is to tear down, or drop all database objects at the beginning of the script and then recreate them. This is not necessarily a solution for all scenarios, but for basic tasks works well for me. To avoid errors I would usually add my drop statements in IF statements, eg:</p> <pre><code>IF EXISTS ( SELECT * FROM information_schema.tables WHERE table_name = 'table' AND table_schema = 'dbo' ) BEGIN DROP TABLE dbo.table END </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload