34,575
社区成员
发帖
与我相关
我的任务
分享
Ⅱ
右击自增字段 → 选择修改(Modify)
→ Identity Specification(自增指定)项
→ 将Is Identify 修改为 No → 保存设置
Ⅲ
UPDATE Ta SET ID = ID * 2 + 3
Ⅳ
右击自增字段 → 选择修改(Modify)
→ Identity Specification(自增指定)项
→ 将Is Identify 修改为 Yes → 保存设置
----Ⅰ查看含自增列的表
SELECT OBJECT_NAME= OBJECT_NAME(OBJECT_ID),Column_NAME = NAME FROM sys.columns
WHERE COLUMNPROPERTY(OBJECT_ID,name,'IsIdentity') > 0
use tempdb
go
create table test
(
id int identity(1,1),
name char(1)
)
go
insert test select 'a'
union all select 'b'
go
select id = 1 * id,name into test_tmp from test
go
truncate table test
go
update test_tmp
set id = id * 2 + 3
go
set identity_insert test on
go
insert test(id,name) select id,name from test_tmp
go
set identity_insert test off
go
select * from test
go
/**
5 a
7 b
**/
drop table test_tmp
drop table test
go
if object_id('tb')is not null drop table tb
go
create table tb(ID int identity(1,1),[Name] varchar(10))
insert tb select 'A'
insert tb select 'B'
insert tb select 'C'
alter table tb
add IDnew int
go
update tb set idnew=id*2+3
go
alter table tb
drop column ID
exec sp_rename 'tb.idnew','ID','column'
go
select * from tb
/*注意: 變更物件名稱的任何部分將會破壞指令碼 (Script) 和預存程序 (Stored Procedure)。
column 重新命名成 'ID'。
Name ID
---------- -----------
A 5
B 7
C 9
*/