zoukankan      html  css  js  c++  java
  • sql表信息查询

    查询每个表的字段及相关信息

    SELECT
    TableName = case when a.colorder=1 then d.name else '' end,
    TableInstruction = case when a.colorder=1 then isnull(f.value,'') else '' end,
    FieldIndex = a.colorder,
    FieldName = a.name,
    Identify = case when COLUMNPROPERTY( a.id,a.name,'IsIdentity')=1 then '√'else '' end, ----标识
    MajorKey = case when exists(SELECT 1 FROM sysobjects where xtype='PK' and parent_obj=a.id 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,
    DataType = b.name,
    Bytesoccupied = a.length, ----占用字节数
    FieldLength = COLUMNPROPERTY(a.id,a.name,'PRECISION'),----长度
    DecimalsNum = isnull(COLUMNPROPERTY(a.id,a.name,'Scale'),0),----小数位数
    CanBeNull = case when a.isnullable=1 then '√'else '' end,
    DefaultValue = isnull(e.text,''),
    FieldInstruction = 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=@Table_Name --如果只查询指定表,加上此where条件,tablename是要查询的表名;去除where条件查询所有的表信息
    order by
    a.id,a.colorder

  • 相关阅读:
    2019省赛训练组队赛4.9周二 2017浙江省赛
    #Leetcode# 49. Group Anagrams
    #Leetcode# 57. Insert Interval
    POJ 2195 Going Home
    HDU 2255 奔小康赚大钱
    HDU 1083 Courses
    HDU 2063 过山车
    POJ 3041 Asteroids
    指针的妙处
    jzoj 6273. 2019.8.4【NOIP提高组A】欠钱 (money)
  • 原文地址:https://www.cnblogs.com/mamaxiaoling/p/11268678.html
Copyright © 2011-2022 走看看