Question about the increment
-
Hi, Simple question : I have a table and one column is ID (int identity(1,1) not null). Say I have 5 rows: [u]ID Name Color [/u] 1 Bob White 2 Jane Black 3 Lucy Red 4 Gang Brown 5 Dub Yellow If I delete the row 3, the remaining ID's are 1, ,2, 4, 5. Is it possible to make the remaining after the deletion row 3 1, 2, 3, 4? that is the above ID's to decrement. __________________ Best regards, Exceter.
-
Hi, Simple question : I have a table and one column is ID (int identity(1,1) not null). Say I have 5 rows: [u]ID Name Color [/u] 1 Bob White 2 Jane Black 3 Lucy Red 4 Gang Brown 5 Dub Yellow If I delete the row 3, the remaining ID's are 1, ,2, 4, 5. Is it possible to make the remaining after the deletion row 3 1, 2, 3, 4? that is the above ID's to decrement. __________________ Best regards, Exceter.
you can make a delete trigger on this table and update recordes with ID > deletedID
-
you can make a delete trigger on this table and update recordes with ID > deletedID
-
Hi, Simple question : I have a table and one column is ID (int identity(1,1) not null). Say I have 5 rows: [u]ID Name Color [/u] 1 Bob White 2 Jane Black 3 Lucy Red 4 Gang Brown 5 Dub Yellow If I delete the row 3, the remaining ID's are 1, ,2, 4, 5. Is it possible to make the remaining after the deletion row 3 1, 2, 3, 4? that is the above ID's to decrement. __________________ Best regards, Exceter.
Why would you want to do this? If your ID column is referenced from somewhere else, you will have to update all those tables too. Let the hole be! Especially if you're using IDENTITY. (It can be done, but will be some work, as you first will have to temporarily SET IDENTITY INSERT ON for your table. Insert row 4 in row 3's place, delete row4, insert row 5 in row 4's place. (Which you offcourse will do in a loop.)) If you really really need this functionality, it is better NOT to use the IDENTITY column, since that will allow you to use an UPDATE statement instead. (Possibly in a trigger or a stored proc...)