Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Administration (2000)
 question about primary key

Author  Topic 

bjurlina
Starting Member

1 Post

Posted - 2004-06-05 : 06:14:47
how can I set my primary key to star again from 1?? for example, if I had a table with some rows in it and I deleted all that rows, next time when I insert a new row in that table, primary key starts from last primary key of previous rows, but I want it to start again from 1.

is that possible??

thanks!

gpl
Posting Yak Master

195 Posts

Posted - 2004-06-05 : 08:27:40
Use
Truncate table <tablename>
This clears out the rows and resets the identity seed
Go to Top of Page

mohdowais
Sheikh of Yak Knowledge

1456 Posts

Posted - 2004-06-05 : 08:55:05
You cannot run a TRUNCATE on a table participating in a foriegn key constraint. In that case you can use DBCC CHECKIDENT, see books online for more details.

OS
Go to Top of Page

derrickleggett
Pointy Haired Yak DBA

4184 Posts

Posted - 2004-06-05 : 16:20:03
DBCC CHECKIDENT('table','RESEED',0)

MeanOldDBA
derrickleggett@hotmail.com

When life gives you a lemon, fire the DBA.
Go to Top of Page
   

- Advertisement -