SQL 語句獲取表字段名稱,屬性

2021-04-14 08:52:06 字數 4546 閱讀 1934

--

獲取表字段名稱,屬性

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')

=1then'√

'else

''end

,主鍵      

=case

when

exists

(select

1from

sysobjects

where

xtype='

pk'andparent_obj

=a.id

andname in(

select

name

from

sysindexes

where

indid

in(

select

indid

from

sysindexkeys

where

id =

a.id

andcolid

=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

ona.xusertype

=b.xusertype

inner

join

sysobjects d

ona.id

=d.id 

andd.xtype='

u'andd.name

<>

'dtproperties

'left

join

syscomments e

ona.cdefault

=e.id

left

join

sysproperties g

ona.id

=g.id

anda.colid

=g.**allid 

left

join

sysproperties f

ond.id

=f.id

andf.**allid=0

where

d.name='

要查詢的表'--

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

order

bya.id,a.colorder

--獲取庫中所有表字段的定義(包括名字,屬性等)

--1. sqlserver資料庫字典--表結構.sql

select

top100

percent

--a.id,

case

when

a.colorder =1

then

d.name

else

''end

as表名,

case

when

a.colorder =1

then

isnull

(f.value,

'')

else

''end

as表說明,

a.colorder

as欄位序號, a.name

as欄位名,

case

when

columnproperty

(a.id,

a.name,

'isidentity')

=1then'√

'else

''end

as標識,

case

when

exists

(select

1from

dbo.sysindexes si

inner

join

dbo.sysindexkeys sik

onsi.id

=sik.id

andsi.indid

=sik.indid

inner

join

dbo.syscolumns sc

onsc.id

=sik.id

andsc.colid

=sik.colid

inner

join

dbo.sysobjects so

onso.name

=so.name

andso.xtype ='

pk'where

sc.id

=a.id

andsc.colid

=a.colid)

then'√

'else

''end

as主鍵,

b.name

as型別, a.length

as長度,

columnproperty

(a.id, a.name,

'precision')

as精度,

isnull

(columnproperty

(a.id, a.name,

'scale

'), 0)

as小數字數,

case

when

a.isnullable =1

then'√

'else

''end

as允許空,

isnull

(e.text

, ''

) as

預設值,

isnull

(g.[

value],

'')

as欄位說明, d.crdate

as建立時間,

case

when

a.colorder =1

then

d.refdate

else

null

endas

更改時間

from

dbo.syscolumns a

left

outer

join

dbo.systypes b

ona.xtype

=b.xusertype

inner

join

dbo.sysobjects d

ona.id

=d.id

andd.xtype ='

u'andd.status

>=

0left

outer

join

dbo.syscomments e

ona.cdefault

=e.id

left

outer

join

dbo.sysproperties g

ona.id

=g.id

anda.colid

=g.**allid

left

outer

join

dbo.sysproperties f

ond.id

=f.id

andf.**allid =0

order

byd.name, a.colorder

查詢oracle表字段名稱

select column name,data type,data length from all tab columns where table name t cakey select from user tables 查詢當前使用者所擁有的表 select from dba tables 擁有d...

Python獲取access表欄位名

以下所有 python2.7 python3.4均可用。一 win32.com author walker date 2015 09 25 summary 列印指定access檔案 指定表的所有字段 import win32com.client def printcolumns win32com p...

Python 獲取 Access 表欄位名!

時效說明 walker 的舊文遷移,某些地方可能過時,最後更新時間為 2015 09 25 以下所有 python2.7 python3.4 均可用。win32.com python資源共享群 484031800 encoding utf 8 author walker date 2015 09 2...