国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發 > 綜合 > 正文

顯示數據庫中的表結構(新增了索引及表的描述信息)

2024-07-21 02:08:31
字體:
來源:轉載
供稿:網友

select
 表名=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 '√'else '' end,
 默認值=isnull(e.text,''),
 字段說明=isnull(g.[value],''),
 索引名稱=isnull(h.索引名稱,''),
 索引順序=isnull(h.排序,'')
from syscolumns a
 left join systypes b on a.xtype=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 sysproperties g on a.id=g.id and a.colid=g.smallid 
 left join sysproperties f on d.id=f.id and f.smallid=0
 left join(--這部分是索引信息,如果要顯示索引與表及字段的對應關系,可以只要此部分
  select 索引名稱=a.name,c.id,d.colid
   ,排序=case indexkey_property(c.id,b.indid,b.keyno,'isdescending')
    when 1 then '降序' when 0 then '升序' end
  from sysindexes a
   join sysindexkeys b on a.id=b.id and a.indid=b.indid
   join (--這里的作用是有多個索引時,取索引號最小的那個
    select id,colid,indid=min(indid) from sysindexkeys
    group by id,colid) b1 on b.id=b1.id and b.colid=b1.colid and b.indid=b1.indid
   join sysobjects c on b.id=c.id and c.xtype='u' and  c.name<>'dtproperties'
   join syscolumns d on b.id=d.id and b.colid=d.colid
  where a.indid not in(0,255)
 ) h on a.id=h.id and a.colid=h.colid
--where d.name='要查詢的表'    --如果只查詢指定表,加上此條件
order by a.id,a.colorder
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 永泰县| 广宁县| 凭祥市| 陆河县| 天峻县| 鹤庆县| 长顺县| 泗水县| 浮山县| 中方县| 常德市| 石家庄市| 清远市| 丰城市| 错那县| 吴堡县| 长白| 呼伦贝尔市| 临湘市| 探索| 北碚区| 宁陵县| 绥棱县| 锦屏县| 远安县| 同仁县| 永春县| 达州市| 文成县| 淮阳县| 武鸣县| 睢宁县| 仁怀市| 张家港市| 寿光市| 集贤县| 普安县| 无极县| 揭东县| 井陉县| 襄垣县|