34,576
社区成员
发帖
与我相关
我的任务
分享
/*添加主键列*/
alter table tb add col int identity primary key
/*删除主键*/
alter table tb drop constraint PK_col
/*删除表中字段*/
alter table tb drop column col
--> 测试数据:[test]
if object_id('[test]') is not null drop table [test]
create table [test](
[工资项目] varchar(4),
[简写] varchar(2),
[金额] int,
[月分] int
)
--添加
alter table test add id int identity primary key
--删除主键
alter table test drop constraint PK__test__3213E83F687E5358
--删除id字段
alter table test drop column id
--主意,添加主键的时候主键字段必须有数据,所以最好是在空表的时候添加,或者这样默认自增