zoukankan      html  css  js  c++  java
  • 获取数据库内所有的表和表内字段的信息

    获取所有的表:

    SELECT OBJECT_NAME (id) FROM sysobjects WHERE xtype = 'U' AND OBJECTPROPERTY (id, 'IsMSShipped') = 0

    获取表内字段的信息:

    SELECT d.name AS c_table, a.colorder AS c_OrderID, a.name AS c_name, a.colstat AS c_IsIdentity, CASE WHEN EXISTS (SELECT 1 FROM sysindexes y, sysindexkeys z WHERE y.id = z.id AND y.indid = z.indid AND z.id = a.id AND z.colid = a.colid AND y.status & 2948 = 2048) THEN '1' ELSE '0' END AS c_IsPK, b.name AS c_type, a.length AS c_ByteNumber, a.prec AS c_Length, ISNULL(a.scale, 0) AS c_DecimalDigits, a.isnullable AS c_IsAllowNull, ISNULL(e.text, '') AS c_Default, ISNULL(g.[value], '') AS c_Description 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 <> 'sysdiagrams' ORDER BY a.id,a.colorder

    获取表和视图内所有的字段信息

    SELECT d.name AS c_table,  a.name AS c_name, a.colstat AS c_IsIdentity, CASE WHEN EXISTS (SELECT 1 FROM sysindexes y, sysindexkeys z WHERE y.id = z.id AND y.indid = z.indid AND z.id = a.id AND z.colid = a.colid AND y.status & 2948 = 2048) THEN '1' ELSE '0' END AS c_IsPK, b.name AS c_type, a.length AS c_ByteLength,   a.isnullable AS c_IsAllowNull 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' or d.xtype='V') 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 <> 'sysdiagrams' ORDER BY a.id,a.colorder

  • 相关阅读:
    solr jvm参数内存自动计算
    记一次使用Chrome修改useragent
    如何查看本机中已安装的.Net Framework版本
    经典实例 PetShop 4.0 For .NET 2.0 下载
    Web.Config配置节加密工具
    some command for Nokia IP 740
    JNCIP进阶OSPF MultiArea Configuration
    寒武纪
    Symantec AntiVirus Corporate Edition 10.0 Error: "Can't communicate with the Server Group..."
    心房客
  • 原文地址:https://www.cnblogs.com/feihusurfer/p/6210271.html
Copyright © 2011-2022 走看看