zoukankan      html  css  js  c++  java
  • 查询字段的默认值

    --使用在SQL2008,***查询字段说明和默认值
    select   object_name(c.id) as 表名   ,c.name as 字段名   ,t.name as 数据类型   ,c.prec as 长度   ,
    p.value as 字段说明   ,m.text as 默认值  
    from syscolumns c   inner join   systypes t   on c.xusertype=t.xusertype   
    left join  sys.extended_properties p   on c.id=p.major_id and c.colid = p.minor_id   
    left join   syscomments m   on c.cdefault=m.id
    -------------------------------------------------------------------------------------------
    select * from sys.extended_properties  --SQL2008 扩展属性表(字段注释,)
    
    
    ----------------------------------------------------------------------------------------------------
    
    /*在sql2000中使用*/
    
    --获取所有默认值:
    
    select   object_name(c.id) as 表名   ,c.name as 字段名   ,t.name as 数据类型   ,c.prec as 长度   ,
    p.value as 字段说明   ,m.text as 默认值  from syscolumns c   
    inner join   systypes t   on c.xusertype=t.xusertype   
    left join    sysproperties p   on c.id=p.id and c.colid = p.smallid   
    left join   syscomments m   on c.cdefault=m.id
    
    --获取单个字段默认值:
    
    select   object_name(c.id) as 表名   ,c.name as 字段名   ,t.name as 数据类型   ,c.prec as 长度   ,
    p.value as 字段说明   ,m.text as 默认值  from syscolumns c   
    inner join   systypes t   on c.xusertype=t.xusertype   
    left join    sysproperties p   on c.id=p.id and c.colid = p.smallid   
    left join   syscomments m   on c.cdefault=m.id  
    where objectproperty(c.id,'IsUserTable')=1   and object_name(c.id) = '表名' and c.name = '字段名称'  
    
    
    
    
    ---------------------------------------------------------------------------------------------------
    --查询指定表的指定字段的默认值
    select   object_name(c.id) as 表名   ,c.name as 字段名   ,t.name as 数据类型   ,c.prec as 长度   ,
    p.value as 字段说明   ,m.text as 默认值  from syscolumns c   
    inner join   systypes t   on c.xusertype=t.xusertype   
    left join  sys.extended_properties p   on c.id=p.major_id and c.colid = p.minor_id    
    left join   syscomments m   on c.cdefault=m.id  
    where objectproperty(c.id,'IsUserTable')=1   and object_name(c.id) = '表名' and c.name = '字段名'  
    
    
    
    
    
    
    
    
    
    
     
     
     
    

      

  • 相关阅读:
    通过一个程序来理解PHP里面的抽象类【1】
    mycheckpoint 把玩手记
    Mysql 大量 unauthenticated user
    零基础学习Oracle 10G视频教程
    mysql show processlist命令 详解
    c# 中的事件
    c# 中方法签名 指的是?
    c# 中的索引
    介绍如何使用C#中的委托
    C# 语法学习笔记
  • 原文地址:https://www.cnblogs.com/accumulater/p/7116224.html
Copyright © 2011-2022 走看看