Wednesday, March 7, 2012

Delete vs. Truncate Table

Using SQL server 2005 express, I am wish to delete data from my table.
I cannot use TRUNCATE TABLE as some tables are referenced by a foreign
key constraint.
So I use
DELETE FROM myTable
This is fine, except that I would like my identification column, to
start again at 1, rather than the last ID +1.
Is there a way of achieving this (ressetting the ID column to its
default value)?
Thank you in advance.> This is fine, except that I would like my identification column, to start
> again at 1, rather than the last ID +1.
> Is there a way of achieving this (ressetting the ID column to its default
> value)?
DBCC CHECKIDENT('table_name', RESEED, 0);|||Check out DBCC CHECKIDENT in BOL|||Thank you both for your help
Emmanuel Petit a crit :
> Using SQL server 2005 express, I am wish to delete data from my table.
> I cannot use TRUNCATE TABLE as some tables are referenced by a foreign
> key constraint.
> So I use
> DELETE FROM myTable
> This is fine, except that I would like my identification column, to
> start again at 1, rather than the last ID +1.
> Is there a way of achieving this (ressetting the ID column to its
> default value)?
> Thank you in advance.

No comments:

Post a Comment