sql sever 设置主键自增长

来源:互联网 发布:免费刷空间访问量软件 编辑:程序博客网 时间:2024/05/19 04:04
SQL Server设置主键自增长列
 
1.新建一数据表,里面有字段id,将id设为为主键
  www.2cto.com  
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;
原创粉丝点击