查詢表結構

2022-03-17 11:03:20 字數 1312 閱讀 8802

select (case when a.colorder=1 then d.name else null end) 表名,

a.colorder 字段序號,a.name 欄位名,

(case when columnproperty( a.id,a.name,'isidentity')=1 then '√' else '' end) 標識,

(case when (select count(*) from sysobjects

where (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)))))))

and (xtype = 'pk'))>0 then '√' else '' end) 主鍵,b.name 型別,a.length 占用位元組數,

columnproperty(a.id,a.name,'precision') as 長度,

isnull(columnproperty(a.id,a.name,'scale'),0) as 小數字數,(case when a.isnullable=1 then '√' else '' end) 允許空,

isnull(e.text,'') 預設值,isnull(g.[value], ' ') as [說明]

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 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.class and f.minor_id=0

where b.name is not null

--where d.name='要查詢的表' --如果只查詢指定表,加上此條件

order by a.id,a.colorder

查詢表結構

在日常生活中,幾乎每天都要進行一些查詢的工作,在 簿中查閱某個人的 號碼 在電腦的資料夾中查詢某個具體的檔案等等。本節主要介紹用於查詢操作的資料結構 查詢表。查詢表是由同一型別的資料元素構成的集合。例如 號碼簿和字典都可以看作是一張查詢表。一般對於查詢表有以下幾種操作 在查詢表中只做查詢操作,而不改...

查詢表結構

方法一 select 序號 c.column id,列名 c.name,是否主鍵 isnull idx.primarykey,n 資料型別 t.name,長度 c.max length,precision c.precision,小數字 c.scale,允許空 case when c.is null...

oracle 查詢表結構

通過資料字典來獲取,select table name,column name,data type,data length from user tab columns where table name not in select view name from user views and table...