zoukankan      html  css  js  c++  java
  • SQLServer判断指定列的默认值是否存在,并修改默认值

    SQLServer判断指定列的默认值是否存在,并修改默认值
    2008年10月21日 星期二 下午 12:08
    if exists(select A.name as DefaultName,B.name as TableName from sysobjects A inner join sysobjects B on A.parent_obj = B.id where A.xtype = 'D' and B.xtype = 'U' and B.name = 'test')
    
    --在SQLserver中判断指定列的默认值是否存在
    alter table test drop constraint trade_default
    
    --因为不能直接修改默认值所以先删除默认值约束
    go 
    alter table test add constraint trade_default default -1 for pid with values
    
    --重新添加新约束,并指定默认值
    go
    
    --如果字段原来无默认值,直接执行如下语句,添加默认值: 
    alter table 表名 add default(1) for 字段名 
    
    --如果原来有默认值,现在要更改默认值,则需要先把原来的默认值drop掉,再添加新的默认值 
    alter table 表名 drop constraint 默认值约束的名称 
    
    --如果不知道默认值约束的名称,用如下语句查询得到: 
    select [name] 
    from sysobjects t 
    where id = (select cdefault from syscolumns where id = object_id(N'表名') 
    and name='字段名')     
    

      

  • 相关阅读:
    postgresql 2012 大会PPT下载 Joe
    Postgresql连接 Joe
    查看Postgresql的连接数 Joe
    greta使用
    CString GetFileDir(const CString& csFile)
    UnicodeToAnsi函数
    myeclipse优化方案
    bool CreatedMultipleDirectory( char* direct)
    LPWSTR GBK(LPCSTR plszUtf8, WCHAR* lpszGBK)
    真正整合资源的高手
  • 原文地址:https://www.cnblogs.com/accumulater/p/7083492.html
Copyright © 2011-2022 走看看