如果要用语句,则参考如下: 有关自增列的相关语句--identity列与普通列互换 CREATE TABLE t1(ID int IDENTITY,A int) GO --插入记录 INSERT t1 VALUES(1) GO--1. 将IDENTITY(标识)列变为普通列 ALTER TABLE t1 ADD ID_temp int GOUPDATE 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 GOEXEC sp_rename N't1_temp',N't1' INSERT t1 VALUES(109999) GO--显示处理结果 SELECT * FROM t1 /*--结果: ID A ----------------- ----------- 1 1 100 9 109999 10 --*/
alter table 表 alter column ID int identity(1,1)
alter table tb alter column ID int identity(1,1) not null PRIMARY KEY --是否需要设置主键
alter table tb alter column id int identity(1,1)
alter table tb alter column ID int identity(1,1) not null PRIMARY KEY
sql2005 SQL Server Management Studio Express中选择你要修改的列查看属性 标示规范 改为 是 就可以了
sql2005 SQL Server Management Studio Express中选择你要修改的列查看属性 标示规范 改为 是 就可以了
有关自增列的相关语句--identity列与普通列互换
CREATE TABLE t1(ID int IDENTITY,A int)
GO
--插入记录
INSERT t1 VALUES(1)
GO--1. 将IDENTITY(标识)列变为普通列
ALTER TABLE t1 ADD ID_temp int
GOUPDATE 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
GOEXEC sp_rename N't1_temp',N't1'
INSERT t1 VALUES(109999)
GO--显示处理结果
SELECT * FROM t1
/*--结果:
ID A
----------------- -----------
1 1
100 9
109999 10
--*/
alter column ID int identity(1,1)
alter column ID int identity(1,1) not null PRIMARY KEY
--是否需要设置主键
alter column id int identity(1,1)
alter table tb
alter column ID int identity(1,1) not null PRIMARY KEY
SQL Server Management Studio Express中选择你要修改的列查看属性 标示规范 改为 是 就可以了
SQL Server Management Studio Express中选择你要修改的列查看属性 标示规范 改为 是 就可以了