|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Hello,
I've a ID column like this: IDcol | Name 273 | namexxx 274 | name xxx 276 | name1 277 | name2 278 | name3 279 | name4 279 | name5 I wish to rename the IDcol filed with -1 to have this: IDcol | Name 273 | namexxx 274 | name xxx 275 | name1 276 | name2 277 | name3 278 | name4 279 | name5 How can I do that into MSSQL? I appreciate your help and time. Regards, Dom |
|
#2
|
|||
|
|||
|
Why? The only purpose of a identity column is to provide unique values.
|
|
#3
|
|||
|
|||
|
Correct, but this is not unique, it's a id from a region table.
This nothing to do with auto-incremant. My exemple is only a extract of my table. Regards, Dom |
|
#4
|
|||
|
|||
|
Ok, I see.
Do you want to get rid of the duplicate id or do you want to fill up all gaps? I.e. if it's only for those specific names shown in the sample, it is easy, Code:
update t set id = id - 1 where name in ('name1','name2','name3','name4')
Otherwise it would probably be easiest to use a cursor (assuming that this is a one time operation). |
|
#5
|
|||
|
|||
|
Cool query. I se, but I've more than 200 lines to renumered (-1)...
Any idea? Dom |
|
#6
|
|||
|
|||
|
No idea for doing with one query since I can't discern any pattern.
|
|
#7
|
||||
|
||||
|
i can't see any pattern either
however, if it's a one-time operation, use a text editor pull out the 200 entries that need to be renumbered (how you know which ones they are is the problem, isn't it?) then just copy/paste them into the code that swampboogie gave in post #4 that would indeed be the fastest way (i speak from experience, having done similar things many times) |
![]() |
| Viewing: Dev Shed Forums > Databases > MS SQL Development > renumber an ID column |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|