SQL 查詢表結構資訊 表字段注釋

2021-08-05 22:30:08 字數 1770 閱讀 1711

--查詢表結構資訊:

select

(case when a.colorder=1 then (i.[name]+'.'+d.[name]) else '' end) 表名,

a.name 欄位名,

isnull(g.[value], ' ') as [說明],

a.colorder 字段序號,

(case when

(select count(1) 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 型別,

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

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,'') 預設值

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.schemas i on d.uid=i.schema_id

where b.name is not null

--and d.name in ('deductinstruction','dun','entry','subject')

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

order by i.[name],d.[name],a.colorder

--查詢本資料庫架構與表名

select (s.[name]+'.'+t.[name]) tb,s.[name] [schema], t.[name] tablename

--,('select * from ['+s.[name]+'].['+t.[name]+'];') ssf

from sys.tables t,sys.schemas s

where t.schema_id = s.schema_id and t.[type] = 'u'

order by s.[name],t.[name]

查詢表字段屬性資訊SQL

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

oracle 查詢表字段明細 字段注釋 表注釋

查詢表字段明細 select column name,data type,data length,data precision data scale from all tab columns where table name tablename 字段注釋 select from user col c...

SQL 修改表字段注釋

sqlserver 表注釋if select count from fn listextendedproperty ms description user n dbo table n maa hinmoku n column n fvhinmezai 0 exec sp updateextended...