ALTER TABLE [USER] ALTER column COL1 INT IDENTITY(1,1) NOT NULL
直接在当前列上用语句貌似实现不了 一般通过 增加列 然后update数据 然后删除列 然后改列名
create table tb ( col1 varchar(100) primary key, col2 varchar(100) )insert into tb select '1111','sdfasdf' union all select '11','sedf' union all select '222','sdf' union all select '11311','gf' alter table tb drop constraint PK__tb__357D0D3E29E1370Aalter table tb alter column col1 int not nullalter table tb add constraint pk_col1 primary key(col1)
#1. 可用SQL直接修改为INT类型的,但无法修改为IDENTITY ALTER TABLE tb1 ALTER COLUMN col1 INT #2. 可在Design视图中修改(Is Identity) 属性为 Yes来达到目的 #3. 要用SQL实现,只能先删除字段,再添加一个新的identity字段
ALTER TABLE [USER]
ALTER column COL1 INT IDENTITY(1,1) NOT NULL
一般通过
增加列 然后update数据
然后删除列
然后改列名
(
col1 varchar(100) primary key,
col2 varchar(100)
)insert into tb
select '1111','sdfasdf' union all
select '11','sedf' union all
select '222','sdf' union all
select '11311','gf' alter table tb
drop constraint PK__tb__357D0D3E29E1370Aalter table tb
alter column col1 int not nullalter table tb
add constraint pk_col1 primary key(col1)
ALTER TABLE tb1
ALTER COLUMN col1 INT
#2. 可在Design视图中修改(Is Identity) 属性为 Yes来达到目的
#3. 要用SQL实现,只能先删除字段,再添加一个新的identity字段