Clearing all data from a table.

mike55

Well-known member
Joined
Mar 26, 2004
Messages
726
Location
Ireland
Hi all

I am currently experimenting with FitNesse, which is an automated acceptance testing tool. Now to run my fit test, I have to clear my database of all the data. I am therefore using "Delete From <<table>>", and replacing <<table>> with the name of the table. Some of my tables have an id column that is auto-incrementing. My questions is therefore, can I reset the column id back to 0 using sql code?

Mike55.
 
Im pretty sure the only way you can do this is by dropping the column and then adding it again.
Code:
ALTER TABLE dbo.MyTable DROP COLUMN MyIdentityCol
ALTER TABLE dbo.MyTable ADD MyIdentityCol int NOT NULL IDENTITY (0, 1)
 
Try something like
Code:
DBCC CHECKIDENT(<<table>>, RESEED, 0)
I used 0 as the seed, of course you may use another value to reseed (same as what you used originally).

Hope this helps!
 
Back
Top