SQL SERVER企业管理器-->右键你的表-->设计表-->选中你要设置标识的字段(必须是int类型)-->下面有个属性叫“标识”的,选“是”,你可以按你的要求改一下标识种子或标识递增量,然后保存该表的设计。
或
create table aa(id int identity(1,1),F1 varchar(20))
或
alter table bb add id int identity(1,1)
或
create table aa(id int identity(1,1),F1 varchar(20))
或
alter table bb add id int identity(1,1)
insert 表 values('CSDNM')select * from 表drop table 表
insert into ai select 1,2
insert into ai select 2,2
insert into ai select 3,2
go
select * from ai
go
alter table ai add UNIQUE(i) /*给列i加入唯一性约束*/
go
select * from ai
go不会有问题得
要是表里面现有数据有违反约束的话
可以用WITH NOCHECK 选项不明白可以看帮助文件