Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

deleting rows

Status
Not open for further replies.

jl3574

Programmer
Jun 5, 2003
76
0
0
CA
i'm trying to delete all the rows in a table in sql server enterprise.
i have a primary key in one of the column with identity=yes
identity seed=1 identtity increment =1

if i have 10 records after i delete them when i enter new records its starts from 11? how do i restart the seed back to 1 when deleting all rows in a table

i was trying to use
"truncate tablename ;"
in sql query but tha's not working?
 
Hi There

Try using this sql statement after the truncate:


DBCC CHECKIDENT(TableName, RESEED, 0)


The path to freedom is seldom trodden by the multitude.
 
Just a note on this which i have posted many times before, it really really really should NOT matter that your key starts from 11, 111 or even 1111! If it matters that the numbers are in perfect order then you are using the identity seed wrong. For example later if you have ten records 1, 2, 3 ... 10

and somebody deletes record numbers 5 and 6, you will have
1,2,3,4,7,8,9,10. But then it really should not matter because it is only a key field.

Transcend
[gorgeous]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top