sql server删除字段约束

--查询指定表的指定约束
select * from sysobjects where parent_obj in(select id from sysobjects where name=‘HIS_QUEUE‘) and name=‘InsertDatedefault‘
--删除约束
IF  EXISTS (SELECT * FROM sys.check_constraints WHERE object_id = OBJECT_ID(N‘[dbo].[CK_DF__HIS_QUEUE__Inser__3A4CA8FD]‘) 
AND parent_object_id = OBJECT_ID(N‘[dbo].[HIS_QUEUE]‘))
ALTER TABLE [dbo].HIS_QUEUE DROP CONSTRAINT DF__HIS_QUEUE__Inser__3A4CA8FD
go
--删除约束
IF  EXISTS (SELECT * FROM sys.check_constraints WHERE object_id = OBJECT_ID(N‘[dbo].[CK_InsertDatedefault]‘) 
AND parent_object_id = OBJECT_ID(N‘[dbo].[HIS_QUEUE]‘))

ALTER TABLE [dbo].HIS_QUEUE DROP CONSTRAINT InsertDatedefault
--print(‘aaaa‘)
go
--新增约束
IF  EXISTS (SELECT * FROM sys.check_constraints WHERE object_id = OBJECT_ID(N‘[dbo].[CK_InsertDatedefault]‘) 
AND parent_object_id = OBJECT_ID(N‘[dbo].[HIS_QUEUE]‘))
ALTER   TABLE   [dbo].[HIS_QUEUE]  ADD   CONSTRAINT   InsertDatedefault   DEFAULT    (GETDATE())   FOR   [InsertDate]
--print(‘bb‘)
go

  

sql server删除字段约束

上一篇:OGG-Oracle 11.2.0.1 ->19.3 pdb 使用Ogg 同步版本相关问题学习整理


下一篇:(转)MySQL 8 新特性之Clone Plugin