sql server设置主键自增长列(新创建表与已存在的表二种情况)
1、新建表,字段id,将id设为为主键
create table tb(id int,constraint pkid primary key (id))
create table tb(id int primary key )
2、新建表,字段id,将id设为主键且自动编号
create table tb(id int identity(1,1),constraint pid primary key (id))
create table tb(id int identity(1,1) primary key )
3、已建好表,字段id,将id设为主键
alter table tb alter column id int not null
alter table tb add constraint pid primary key (id)
4、删除主键
use Movies
go
alter table changePassword drop constraint pid;