Snippet取表字段說明和詳細資訊

2022-02-26 18:34:01 字數 1709 閱讀 2277

if object_id (n'dbo.getdetails', n'if') is not null

drop function dbo.getdetails;

gocreate function dbo.getdetails(@name nvarchar(200))

returns table

asreturn

(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 parent_obj=a.id 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],'')

from syscolumns a

left join systypes b on a.xusertype=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.major_id and f.minor_id=0

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

來自為知筆記(wiz)

SQL取表字段的方法

返回當前環境中可查詢的指定表或檢視的列資訊。語法sp columns table name object 表名或檢視名 table owner owner 物件擁有者 table qualifier qualifier 資料庫名 column name column 欄位名 odbcver odbc...

不同版本SQL Sever 表字段說明

以前自己做了乙個資料表實體化工具,說白了就是根據sql server資料庫表生成相應的實體類,同時標註各個屬性的xml注釋。一般開發流程是使用powerdesigner設計資料庫表結構,當然備註了各個欄位的說明,在生成物理資料庫時,各個表字段都會在說明部分攜帶漢語說明。在sql2000下面字段說明是...

MySQL合併資料和給表,欄位取別名

union關鍵字 select s id,f name,f price from fruits where f price 9.0 union all select s id,f name,f price from fruits where s id in 101,103 為表取別名 select ...