zoukankan      html  css  js  c++  java
  • 获取、更新字段默认值

    今天整理以前的资料,看到这个东西,挺偏门,记录下备忘吧。感谢园子里的朋友们。

    DECLARE @ConsName VARCHAR(1000) ,
        @tableName VARCHAR(1000) ,
        @colName VARCHAR(1000)  
    
    
    SELECT  @tableName = N'myOrder' ,
            @colName = 'ShipCountry'
    
    SELECT  @ConsName = b.name
    FROM    syscolumns a ,
            sysobjects b
    WHERE   a.id = OBJECT_ID('myOrder')
            AND b.id = a.cdefault
            AND a.name = @colName
            AND b.name LIKE 'DF%' 
    
    
    EXEC('alter table '+@tableName+ ' drop constraint '+@ConsName)
    
    EXEC('ALTER TABLE '+@tableName+ ' ADD CONSTRAINT '+@ConsName+' DEFAULT (N''Italy'')  FOR '+@colName)

    有更改,那查询就必须有的嘛。

    -- =============================================
    -- 获取表字段的默认值
    -- =============================================
    
    SELECT COLUMN_DEFAULT  FROM      INFORMATION_SCHEMA.COLUMNS  WHERE     TABLE_NAME = 'Employees' 
    
    
    -- =============================================
    -- 获取有默认值的字段
    -- =============================================
    
    SELECT  SO.NAME AS Name ,
            SC.NAME AS ColumnName ,
            SM.TEXT AS DefaultValue
    FROM    dbo.sysobjects SO
            INNER JOIN dbo.syscolumns SC ON SO.id = SC.id
            LEFT JOIN dbo.syscomments SM ON SC.cdefault = SM.id
    WHERE   SO.xtype = 'U'
            AND SM.TEXT IS NOT NULL -- AND SO.name='AuctionTstOrder'
    ORDER BY SO.[name] ,
            SC.colid 
  • 相关阅读:
    大数据集群环境ssh免密码登录设置
    FreeRTOS任务创建删除
    BLE外设设计
    BLE控制器之链路层
    BLE控制器之链路层二
    BLE控制器之物理层特性
    BLE基本理论和概念
    BLE主机之ATT和GATT
    BLE主机之SM层
    BLE主机之L2CAP层
  • 原文地址:https://www.cnblogs.com/mfkaudx/p/3664412.html
Copyright © 2011-2022 走看看