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 = '字段名'  
    
    
    
    
    
    
    
    
    
    
     
     
     
    

      

  • 相关阅读:
    jms版本
    2-9 Mybatis-Plus之CRUD演示二
    2-8 Mybatis-Plus之CRUD演示一
    2-7 Mybatis-Plus代码生成器演示
    2-6 Mybatis-Plus配置和代码生成器解析
    2-5 Mybatis-Plus配置文件详解
    2-4 Mybatis-Plus框架介绍
    2-3 项目基础环境构建
    2-2 项目结构介绍和框架选择
    2-1 章节及基础环境介绍
  • 原文地址:https://www.cnblogs.com/accumulater/p/7116224.html
Copyright © 2011-2022 走看看