如何在sql server中插入数据后更改id系列 [英] how to change the series of id after insert data in sql server

查看:125
本文介绍了如何在sql server中插入数据后更改id系列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含一些数据的表,在这个表中id不是自动增量。数据是:

Id名称

1 abc

2 def

3 ghi



i希望改变系列形式1,2,3 ...到101,102,103 ......通过查询

i想改变我的表格如下:

Id名称

101 abc

102 def

103 ghi





帮助我解决这个问题

Thanx与问候

Ankush Sharma

i have a table with some data, in this table id in not auto increment. Data is:
Id Name
1 abc
2 def
3 ghi

i want change the series form 1,2,3... to 101,102,103... through query
i want change my table like:
Id Name
101 abc
102 def
103 ghi


Help me to solve that problem
Thanx with Regards
Ankush Sharma

推荐答案

试试这个会把你的系列变成所需的

try this this will turn your series to the desired
update subject set subjectid=subjectid+100 
where subjectid=subjectid


UPDATE表

SET id = 100 + id

FROM table
UPDATE table
SET id = 100 + id
FROM table


声明@temp int

set @ temp = 0

while(@ temp< 3)

begin

update tbl s et ID = @ temp + 100 + ID其中ID = 1 + @ temp

set @ temp = @ temp + 1

end
declare @temp int
set @temp=0
while(@temp<3)
begin
update tbl set ID=@temp+100+ID where ID=1+@temp
set @temp=@temp+1
end


这篇关于如何在sql server中插入数据后更改id系列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆