熱點推薦:
您现在的位置: 電腦知識網 >> 編程 >> SQL Server >> 正文

數據庫手邊系列:SQL Server數據表信息

2022-06-13   來源: SQL Server 

  SELECT
  
  表名=case when lorder= then dname else end
  
  表說明=case when lorder= then isnull(fvalue) else end
  
  字段序號=lorder
  
  字段名=aname
  
  標識=case when COLUMNPROPERTY( aidanameIsIdentity)= then else end
  
  主鍵=case when exists(SELECT FROM sysobjects where xtype=PK and name in (
  
  SELECT name FROM sysindexes WHERE indid in(
  
  SELECT indid FROM sysindexkeys WHERE id = aid AND colid=lid
  
  ))) then else end
  
  類型=bname
  
  占用字節數=alength
  
  長度=COLUMNPROPERTY(aidanamePRECISION)
  
  小數位數=isnull(COLUMNPROPERTY(aidanameScale))
  
  允許空=case when aisnullable= then else end
  
  默認值=isnull(etext)
  
  字段說明=isnull(g[value])
  
  FROM syscolumns a
  
  left join systypes b on axtype=bxusertype
  
  inner join sysobjects d on aid=did and dxtype=U and dname<>dtproperties
  
  left join syscomments e on acdefault=eid
  
  left join sysproperties g on aid=gid and lid=gsmallid
  
  left join sysproperties f on did=fid and fsmallid=
  
  where dname=要查詢的表 如果只查詢指定表加上此條件
  
  order by aidlorder
From:http://tw.wingwit.com/Article/program/SQLServer/201311/22170.html
    推薦文章
    Copyright © 2005-2022 電腦知識網 Computer Knowledge   All rights reserved.