• 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
    

      

    博客内容主要用于日常学习记录,内容比较随意,如有问题,还需谅解!!!
  • 相关阅读:
    Nginx使用
    MySQL 分区
    php PDO预处理
    php
    php
    linux 下编译安装MySQL
    php 工厂模式
    MySQL 权限管理
    hadoop集群安装20181016(20111130:前面太忙,没有写完,后面继续)
    JavaScript函数参数翻转——连接多个数组——zip、zipwith
  • 原文地址:https://www.cnblogs.com/YYkun/p/14779815.html
Copyright © 2020-2023  润新知