SQL Server匯出表結構 資料字典

2021-09-29 13:26:16 字數 1292 閱讀 1859

select

(case when a.colorder=1 then d.name else '' 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.major_id

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

order by a.id,a.colorder

SqlServer匯出表結構

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,字段說明 isnull g...

sql server 匯出表結構

一 執行如下sql server指令碼 可直接執行 select 表名 case when a colorder 1 then d name else end,表說明 case when a colorder 1 then isnull f value,else end,字段序號 a.colorde...

sqlserver匯出表結構說明

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 ...