zoukankan      html  css  js  c++  java
  • 【SQL】查询表结构和字段说明语句

    SELECT tableName=CASE WHEN a.colorder=1 THEN d.name ELSE '' END 
    ,表说明 =CASE WHEN a.colorder=1 THEN ISNULL(f.value,'') ELSE '' END
    ,字段序号=a.colorder
    ,字段名 =a.name 
    ,标识  =CASE WHEN COLUMNPROPERTY( a.id,a.name,'IsIdentity')=1 THEN '√'ELSE '' END 
     ,主键  =CASE WHEN EXISTS(SELECT 1 FROM sysobjects WHERE xtype='PK' AND name IN (
     SELECT name FROM sysindexes WHERE indid IN(  
    SELECT indid FROM sysindexkeys WHERE id = a.id AND colid=a.colid
      ))) THEN '√' ELSE '' END  ,类型  =b.name  ,占用字节=a.length  ,长度  =COLUMNPROPERTY(a.id,a.name,'PRECISION') 
       ,小数位数=ISNULL(COLUMNPROPERTY(a.id,a.name,'Scale'),0) 
        ,允许空 =CASE WHEN a.isnullable=1 THEN '1'ELSE '' END 
         ,默认值 =ISNULL(e.text,'')  ,字段说明=ISNULL(g.[value],'') 
         FROM syscolumns a 
         LEFT JOIN systypes b ON a.xusertype=b.xusertype 
         INNER JOIN sysobjects d ON a.id=d.id AND d.xtype='U' AND d.name<>'dtproperties' 
         LEFT JOIN syscomments e ON a.cdefault=e.id
         LEFT JOIN sys.extended_properties g ON a.id=g.major_id AND a.colid=g.minor_id 
         LEFT JOIN sys.extended_properties f 
      ON d.id=f.major_id AND f.minor_id=0 WHERE d.name='Account'  ORDER BY a.id,a.colorder asc
    本文版权归作者和博客园共有,欢迎转载,但必须给出原文链接,并保留此段声明,否则保留追究法律责任的权利。
    嗨,如果有问题可以加QQ:1058848735 询问的哦,技术的道路上,求知求解共同探讨
  • 相关阅读:
    抽象类和接口
    Thread线程
    ArrayList、Vector和LinkedList
    Java并发编程:Callable、Future和FutureTask
    java开发JDBC连接数据库代码
    @Async的简单用法总结
    微信/企业微信的分享功能
    IOS11 底部输入框被手机输入法遮住
    MySQL 数据库设计总结
    Java 多个文件压缩下载
  • 原文地址:https://www.cnblogs.com/sopcce/p/8051490.html
Copyright © 2011-2022 走看看