你的位置:首页 > 软件开发 > 数据库 > SQL更改表字段为自增标识

SQL更改表字段为自增标识

发布时间:2016-05-30 18:00:10
下面是SQL语句:--删除主键约束DECLARE @Constraint_Name varchar (200) select @Constraint_Name = Name from dbo.sysobjectswhere Xtype = PK and Parent_Obj ...

下面是SQL语句:

--删除主键约束DECLARE @Constraint_Name varchar (200) select @Constraint_Name = Name from dbo.sysobjectswhere Xtype = 'PK' and Parent_Obj =(select [ID] from dbo.sysobjectswhere id = object_id(N'[表名称]')and OBJECTPROPERTY(id, N'IsUserTable') = 1) if @Constraint_Name <> ''beginalter table 表名称 drop constraint @Constraint_Nameend--删除主键字段-- 何问起 hovertree.com declare @count intselect @count = count(*) from sysobjects a,syscolumns bwhere a.id = b.id and b.name = '主键字段名' and a.Name = '表名称'if @count > 0beginalter table 表名称 drop column 主键字段名 end--创建字段,主键,并自增alter table 表名称 add 主键字段名 int identity(1,1) PRIMARY KEY

原标题:SQL更改表字段为自增标识

关键词:sql

sql
*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们: admin#shaoqun.com (#换成@)。