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.
Author |
Topic |
learning_grsql
Posting Yak Master
230 Posts |
Posted - 2013-06-01 : 18:12:21
|
I have columns similar to below.As you see below, when rows are deleted the id nos. are not in series. How can I rearrange it to 1,2,3,4,5 again?[CODE]id | column11 | values2 | values5 | values6 | values10 | values[/CODE] |
|
pascal_jimi
Posting Yak Master
167 Posts |
Posted - 2013-06-01 : 18:19:26
|
CREATE TABLE TableID (ID INT IDENTITY(1,1), Col VARCHAR(10))GO/* Insert 10 records with first value */INSERT INTO TableID (Col)VALUES ('First')GO 10/* Check the records in table */SELECT *FROM TableIDGO/* Delete last few records */DELETEFROM TableIDWHERE ID IN (8,9,10)GO/* Check the records in table */SELECT *FROM TableIDGO/* Get current Max Value and reseed table */DECLARE @MaxID INTSELECT @MaxID = MAX(ID)FROM TableIDDBCC CHECKIDENT('TableID', RESEED, @MaxID)GO/* Insert 10 records with second value */INSERT INTO TableID (Col)VALUES ('Second')GO 5/* Check the records in table */SELECT *FROM TableIDGO/* Clean Database */DROP TABLE TableIDGOkmkmmm |
 |
|
pascal_jimi
Posting Yak Master
167 Posts |
Posted - 2013-06-01 : 18:20:01
|
http://blog.sqlauthority.com/2009/04/01/sql-server-reseed-identity-of-table-table-missing-identity-values-gap-in-identity-column/kmkmmm |
 |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
|
|
|
|