zoukankan      html  css  js  c++  java
  • 得到数据库字段信息

    USE database1
    SELECT
      表名  
    = CASE a.colorder WHEN 1 THEN c.name ELSE '' END,
      序    
    = a.colorder,
      字段名
    = a.name,
      标识  
    = CASE COLUMNPROPERTY(a.id,a.name,'IsIdentity') WHEN 1 THEN '' ELSE '' END,
      主键  
    = CASE
       
    WHEN EXISTS (
         
    SELECT *
         
    FROM sysobjects
         
    WHERE xtype='PK' AND name IN (
           
    SELECT name
           
    FROM sysindexes WHERE id=a.id AND indid IN (
             
    SELECT indid
             
    FROM sysindexkeys
             
    WHERE id=a.id AND colid IN (
               
    SELECT colid
               
    FROM syscolumns
               
    WHERE id=a.id AND name=a.name
              )
            )
          )
        )
       
    THEN ''
       
    ELSE ''
     
    END,
      类型  
    = b.name,
      字节数
    = a.length,
      长度  
    = COLUMNPROPERTY(a.id,a.name,'Precision'),
      小数  
    = CASE ISNULL(COLUMNPROPERTY(a.id,a.name,'Scale'),0)
       
    WHEN 0 THEN ''
       
    ELSE CAST(COLUMNPROPERTY(a.id,a.name,'Scale') AS VARCHAR)
     
    END,
      允许空
    = CASE a.isnullable WHEN 1 THEN '' ELSE '' END,
      默认值
    = ISNULL(d.[text],''),
      说明  
    = ISNULL(e.[value],'')
    FROM syscolumns a
     
    LEFT  JOIN systypes      b ON a.xtype=b.xusertype
     
    INNER JOIN sysobjects    c ON a.id=c.id AND c.xtype='U' AND c.name<>'dtproperties'
     
    LEFT  JOIN syscomments   d ON a.cdefault=d.id
     
    LEFT  JOIN sysproperties e ON a.id=e.id AND a.colid=e.smallid
    ORDER BY c.name, a.colorder

     

    上边的代码,在SQL2005中,字段说明sysproperties 不存在. 好像是extends_properties

  • 相关阅读:
    分形与数据结构第一篇(神奇的色子)
    画图小工具第二篇
    画图小工具第一篇
    图形界面第一篇
    回合制对战游戏第二篇
    回合对战制游戏第一篇(初识java)
    技术+态度+人品
    排序的一些方法(稳定性,内外排序,时间空间复杂度)
    暂时性死区
    vue传值(父子传值,非父子传值)
  • 原文地址:https://www.cnblogs.com/hanf/p/1717086.html
Copyright © 2011-2022 走看看