方法1:  创建表时同时设置主键自增

create table <表名>  (  
    <字段1-主键自增> int identity (1,1) primary key,  
    <字段2> varchar(100) unique,  
    .....
) 

方法2:  重新添加一列具有identity属性字段(因自增列不能修改)

alter table <表名> drop column <自增字段名>
alter table <表名> add <自增字段名> int identity(1,1)

Logo

为开发者提供学习成长、分享交流、生态实践、资源工具等服务,帮助开发者快速成长。

更多推荐