獲取表描述資訊

2022-03-15 00:27:46 字數 3227 閱讀 1529

create

view

v_table_des

asselect表名=

o.name,

表描述=ptb.[

value],

字段序號

=c.column_id,

欄位名=c.name,

字段描述

=isnull(pfd.[

value

],n''

), 主鍵

=isnull(idx.primarykey,0

), 可空

=c.is_nullable,

型別=t.name,

長度=c.max_length,

識別符號=c.is_identity,

預設值=isnull(d.definition,n''

), computed

=case

when c.is_computed=

1then n'√'

else n''

end,

小數字=c.precision

, scale

=c.scale,

indexname

=isnull(idx.indexname,n''

), indexsort

=isnull(idx.sort,n''

), create_date

=o.create_date,

modify_date

=o.modify_date

from

sys.columns c

inner

join

sys.objects o

on c.[

object_id

]=o.[

object_id

]and o.type='u

'and o.is_ms_shipped=

0inner

join

sys.types t

on c.user_type_id=

t.user_type_id

left

join

sys.default_constraints d

on c.[

object_id]=

d.parent_object_id

and c.column_id=

d.parent_column_id

and c.default_object_id=d.[

object_id

]left

join

sys.extended_properties pfd

on pfd.class=

1and c.[

object_id]=

pfd.major_id

and c.column_id=

pfd.minor_id

--and pfd.name='caption' -- 字段說明對應的描述名稱(乙個字段可以新增多個不同name的描述)

left

join

sys.extended_properties ptb

on ptb.class=

1and ptb.minor_id=

0and c.[

object_id]=

ptb.major_id

--and pfd.name='caption' -- 表說明對應的描述名稱(乙個表可以新增多個不同name的描述)

left

join

--索引及主鍵資訊

(

select

idxc.

[object_id],

idxc.column_id,

sort

=case indexkey_property(idxc.[

object_id

],idxc.index_id,idxc.index_column_id,'

isdescending')

when

1then

'desc

'when

0then

'asc

'else

''end

, primarykey

=idx.is_primary_key,

indexname

=idx.name

from

sys.indexes idx

inner

join

sys.index_columns idxc

on idx.[

object_id

]=idxc.[

object_id

]and idx.index_id=

idxc.index_id

left

join

sys.key_constraints kc

on idx.[

object_id

]=kc.[

parent_object_id

]and idx.index_id=

kc.unique_index_id

inner

join

--對於乙個列包含多個索引的情況,只顯示第個索引資訊

(

select

[object_id

], column_id, index_id=

min(index_id)

from

sys.index_columns

groupby[

object_id

], column_id

) idxcuq

on idxc.[

object_id

]=idxcuq.[

object_id

]and idxc.column_id=

idxcuq.column_id

and idxc.index_id=

idxcuq.index_id

) idx

on c.[

object_id

]=idx.[

object_id

]and c.column_id=

idx.column_id

where o.name like

'arp_%'--

如果只查詢指定表,加上此條件

Mysql 獲取表資訊 獲取表詳情

查詢資料庫表結構 select table schema as 資料庫名 table name as 資料表名 create time as 建立時間 table comment as 描述 from information schema.tables where table schema 資料庫名...

Enum 列舉值 (一) 獲取描述資訊

封裝了方法 public static class enumoperate public basedescriptionattribute string descriptioncn,string descriptionen base descriptioncn private string desc...

MySQL獲取表的部分描述

專案要求寫資料庫設計說明文件,其中要求的描述字段如下 字段 型別 null key 預設 注釋 main line require id bigint 16 yes主線路需求id date datetime yes日期 business mode varchar 30 yes運營模式 create ...