identity(seed,numIncrement)
--创建测试表
CREATE TABLE t1(ID int IDENTITY,A int)
GO
--插入记录
INSERT t1 VALUES(1)
GO
--1. 将IDENTITY(标识)列变为普通列
ALTER TABLE t1 ADD ID_temp int
GO
UPDATE t1 SET ID_temp=ID
ALTER TABLE t1 DROP COLUMN ID
EXEC sp_rename N't1.ID_temp',N'ID',N'COLUMN'
INSERT t1 VALUES(100,9)
GO
--2. 将普通列变为标识列
CREATE TABLE t1_temp(ID int,A int IDENTITY)
SET IDENTITY_INSERT t1_temp ON
INSERT t1_temp(ID,A) SELECT * FROM t1
SET IDENTITY_INSERT t1_temp OFF
DROP TABLE T1
GO
EXEC sp_rename N't1_temp',N't1'
INSERT t1 VALUES(109999)
本文介绍如何在 SQL Server 中将标识 (IDENTITY) 列转换为普通列,以及如何将普通列转换为标识列。通过具体步骤展示转换过程,并提供实际使用的 T-SQL 代码。
1944

被折叠的 条评论
为什么被折叠?



