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 |
|
luarit
Starting Member
6 Posts |
Posted - 2012-01-09 : 14:02:46
|
| Hello All,I have a question about Update statements.If I have a table called table1Id Name 1 A2 B3 C4 D5 E6 FAnd I wan to change it to this oneId Name 2 A3 B4 C5 D6 E7 FOf course my table is more complicated, my idea wasupdate table1 set Id=2 where Id=1;update table1 set Id=3 where Id=2;update table1 set Id=4 where Id=3;update table1 set Id=5 where Id=4;update table1 set Id=6 where Id=5;update table1 set Id=7 where Id=6;My problem is that the first Update will do 2 rows with Id=2, the second one, will do 3 rows with Id=3,...Is there any way to do that correctly?Thanks |
|
|
X002548
Not Just a Number
15586 Posts |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2012-01-10 : 04:00:48
|
| is id your primary key column?------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2012-01-10 : 04:45:09
|
is id an identity column ? KH[spoiler]Time is always against us[/spoiler] |
 |
|
|
luarit
Starting Member
6 Posts |
Posted - 2012-01-10 : 05:52:05
|
| Yes, it was my primary key, I want to merging several database in only one. I give this example but it is not always adding +1 some times Id=2 will be 4,... |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2012-01-10 : 06:50:44
|
quote: Originally posted by luarit Yes, it was my primary key, I want to merging several database in only one. I give this example but it is not always adding +1 some times Id=2 will be 4,...
why do you need to shift records like this? are you trying to fill up gaps? i dont think this is required at all------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
|
|
|
|
|