1: alter table 表名 add constraint 主键名 primary key (字段或字段组合) ALTER TABLE 表名 DROP CONSTRAINT 主键名2:如何用语句添加或去除表字段的自增属性 http://expert.csdn.net/Expert/topic/2217/2217137.xml?temp=.8302118
1.如何把一个表的建立表的主键和主键取消掉 加: alter table t1 add constraint pk_1 primary key (a,b) 删: alter table t1 drop constraint pk_12.如何把有几个主键的表某一个字段类型改变 如把identity 改为 非自增的 int 有数据的话 alter table t1 drop constraint pk_1 go ALTER TABLE 表 ADD 编号1 bigint identity(1,1) not null go SET IDENTITY_INSERT 表 ON go update 表 set 编号1=编号 go SET IDENTITY_INSERT 表 OFF go ALTER TABLE 表 DROP COLUMN 编号 go exec sp_rename '表.编号1','编号' go alter table t1 add constraint pk_1 primary key (a,b)
需要先保存数据到临时表,删除该字段,然后将数据导回来.
建议用企业管理器操作.
你也可以查看企业管理器的操作脚本.实质就是和上面说的一样.
alter table 表名 add constraint 主键名 primary key (字段或字段组合)
ALTER TABLE 表名 DROP CONSTRAINT 主键名2:如何用语句添加或去除表字段的自增属性
http://expert.csdn.net/Expert/topic/2217/2217137.xml?temp=.8302118
加:
alter table t1 add constraint pk_1 primary key (a,b)
删:
alter table t1 drop constraint pk_12.如何把有几个主键的表某一个字段类型改变 如把identity 改为 非自增的 int
有数据的话
alter table t1 drop constraint pk_1
go
ALTER TABLE 表 ADD 编号1 bigint identity(1,1) not null
go
SET IDENTITY_INSERT 表 ON
go
update 表 set 编号1=编号
go
SET IDENTITY_INSERT 表 OFF
go
ALTER TABLE 表 DROP COLUMN 编号
go
exec sp_rename '表.编号1','编号'
go
alter table t1 add constraint pk_1 primary key (a,b)