MS SQL2000 2005轉出資料字典

2021-09-05 20:18:44 字數 3686 閱讀 4433

sql 2000

select

(case

when

a.colorder=1

then

d.name 

else

''end

)表名, 

a.colorder欄位序號, 

a.name欄位名, 

(case

when

columnproperty

( a.id,a.name,

'isidentity')

=1then'√

'else

''end

)標識, 

(case

when

(select

count(*

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

0then'√

'else

''end

)主鍵, 

b.name型別, 

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

)預設值, 

isnull

(g.[

value],

'') as欄位說明 

from

syscolumns a 

left

join

systypes b 

ona.xtype

=b.xusertype 

inner

join

sysobjects d 

ona.id

=d.id 

andd.xtype='

u'anda .name

<>

'dtproperties

'left

join

syscomments e 

ona.cdefault

=e.id 

left

join

sysproperties g 

ona.id

=g.id 

anda.colid 

=g.smallid 

order

bya.id,a.colorder

sql 2005

select

(case

when

a.colorder=1

then

d.name 

else

''end

)表名, 

a.colorder欄位序號, 

a.name欄位名, 

(case

when

columnproperty

( a.id,a.name,

'isidentity')

=1then'√

'else

''end

)標識, 

(case

when

(select

count(*

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

0then'√

'else

''end

)主鍵, 

b.name型別, 

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

)預設值, 

isnull

(g.[

value],

'') as欄位說明 

from

syscolumns a 

left

join

systypes b 

ona.xtype

=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

sys.extended_properties g 

ona.id

=g.major_id 

anda.colid 

=g.major_id 

order

bya.id,a.colorder

轉自:

MSSQL縱列轉橫列

在工作中我們一般會遇到將縱列轉橫列的需求,具體 1.建表 create table dbo acrosschangeendlong id int identity 1,1 not null name nvarchar 50 not null subject nvarchar 50 not null ...

MSSQL 本週 本月 本年 轉 修)

本週 起 dateadd wk,datediff wk,0,getdate 1 止 dateadd wk,datediff wk,0,getdate 6 本月 起 dateadd mm,datediff mm,0,getdate 0 止 dateadd ms,3,dateadd mm,datedif...

MS SQL 日期轉字元全格式

select convert varchar 100 getdate 0 07 16 2012 10 57am select convert varchar 100 getdate 1 07 16 12 select convert varchar 100 getdate 2 12.07.16 se...