34,591
社区成员
发帖
与我相关
我的任务
分享
alter table t1 alter column id int not null --先设置为NOT NULL
alter table t1 add constraint PK_T1 primary key (id)
if object_id('tb') is not null
drop table tb
go
create table tb
(
id int,
name varchar(10)
)
go
--设置主键
--先设置列为非空,然后才能设置主键
alter table tb alter column id int not null
go
alter table tb add CONSTRAINT pk_tb_id PRIMARY KEY (id)
--删除name列
alter table tb drop column name
--删除表
drop table tb