SqlServer欄位說明查詢(表基本資訊查詢)

2022-02-26 22:34:04 字數 2534 閱讀 1487

--

快速檢視表結構(比較全面的)

select

case

when col.colorder =

1then

obj.name

else

''end

as表名,

col.colorder

as序號 ,

col.name

as列名 ,

isnull(ep.[

value

], '') as

列說明 ,

t.name

as資料型別 ,

col.length

as長度 ,

isnull(columnproperty(col.id, col.name, '

scale

'), 0) as

小數字數 ,

case

when

columnproperty(col.id, col.name, '

isidentity

') =

1then'√

'else

''end

as標識 ,

case

when

exists ( select

1from

dbo.sysindexes si

inner

join dbo.sysindexkeys sik on si.id =

sik.id

and si.indid =

sik.indid

inner

join dbo.syscolumns sc on sc.id =

sik.id

and sc.colid =

sik.colid

inner

join dbo.sysobjects so on so.name =

si.name

and so.xtype ='pk

'where sc.id =

col.id

and sc.colid = col.colid ) then'√

'else

''end

as主鍵 ,

case

when col.isnullable =

1then'√

'else

''end

as允許空 ,

isnull(comm.text, '') as

預設值from

dbo.syscolumns col

left

join dbo.systypes t on col.xtype =

t.xusertype

inner

join dbo.sysobjects obj on col.id =

obj.id

and obj.xtype ='u

'and obj.status >=

0left

join dbo.syscomments comm on col.cdefault =

comm.id

left

join sys.extended_properties ep on col.id =

ep.major_id

and col.colid =

ep.minor_id

and ep.name =

'ms_description

'left

join sys.extended_properties eptwo on obj.id =

eptwo.major_id

and eptwo.minor_id =

0and eptwo.name =

'ms_description

'where obj.name =

'egression'--

表名order

by col.colorder ;

上面**適用於sqlserver資料庫,只需要更改表名-->執行**就可以獲得表的基本資訊(**來自網路:

下面是簡單**(未測試)

select t.[

name

]as 表名,c.[

name

]as 欄位名,cast(ep.[

value]as

varchar(100)) as

[字段說明

]from sys.tables ast

inner

join

sys.columns

as c on t.object_id

= c.object_id

left

join sys.extended_properties as

ep

on ep.major_id = c.object_id

and ep.minor_id = c.column_id where ep.class =

1and t.name=

'tablename

'

mysql explain查詢結果字段說明

1 id 這是select的查詢序列號 2 select type select type就是select的型別,可以有以下幾種 簡單select 不使用union或子查詢等 primary 最外面的select union union中的第二個或後面的select語句 dependent unio...

sqlserver2005查詢字段資訊

select case when a.colorder 1 then d.name else end as 表名,a.colorder as 字段序號,a.name as 欄位名,case when columnproperty a.id,a.name,isidentity 1 then else ...

SQL SERVER查詢欄位在哪個表裡

declare columnname asvarchar 100 set columnname 欄位名的模糊匹配 select表名 d.name,表說明 case when a.colorder 1then isnull f.value,else end,字段序號 a.colorder,欄位名 a....