--查询指定表的指定约束 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