mssql資料庫匯出表明欄位名和說明到Excel

2021-07-11 15:35:33 字數 3241 閱讀 6278

一下語句都是在你要匯出的那個資料庫查詢

-------------------------sql2005以下用這個------------------------------

select

(case when a.colorder=1 then d.name else '' end)表名,

a.colorder 字段序號,

a.name 欄位名,

(case when columnproperty( a.id,a.name,'isidentity')=1 then '√'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'))>0 then '√' 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

on  a.xtype=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 sysproperties g

on a.id=g.id and a.colid = g.smallid 

order by a.id,a.colorder

------------------------sql2005以上用下面--------------------------

1.首選執行這個下面生成乙個檢視

if exists (select 1  

from  sysobjects  

where  name = 'sysproperties'  

and   xtype = 'v')  

begin  

drop view sysproperties  

end  

go  

create view sysproperties  

as  

select a.name as tablename,a.id as tableid,b.name as colname,b.colid as colid,b.xtype as coltype,c.name as propname,c.value as propvalue  

from sysobjects as a   

inner join syscolumns as b on a.id = b.id  

inner join sys.extended_properties as c on c.major_id = a.id and ( minor_id = b.colid)  

2.在執行下面

select

(case when a.colorder=1 then d.name else '' end)表名,

a.colorder 字段序號,

a.name 欄位名,

(case when columnproperty( a.id,a.name,'isidentity')=1 then '√'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'))>0 then '√' 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.[propvalue],'') as 字段說明   

from  syscolumns  a left join systypes b

on  a.xtype=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 sysproperties g

on a.id=g.tableid and a.colid = g.colid 

order by a.id,a.colorder

資料庫命名規範(表 欄位名)

資料庫命名規範 一 實體和屬性的命名 1 常用單詞已經進行了縮寫,在命名過程當中,根據語義拼湊縮寫即可。注意,由於orcal資料庫會將欄位名稱統一成大寫或者小寫中的一種,所以要求加上下劃線 舉例 定義的縮寫 sales sal 銷售 order ord 訂單 detail dtl 明細 則銷售訂單名...

資料庫命名規範(表 欄位名)

資料庫命名規範 一 實體和屬性的命名 1 常用單詞已經進行了縮寫,在命名過程當中,根據語義拼湊縮寫即可。注意,由於orcal資料庫會將欄位名稱統一成大寫或者小寫中的一種,所以要求加上下劃線 舉例 定義的縮寫 sales sal 銷售 order ord 訂單 detail dtl 明細 則銷售訂單名...

ASP獲取資料庫表名,欄位名

在asp論壇上看到很多問怎麼獲取資料庫表名,欄位名以及如何對欄位進行刪除,增添的操作故寫此文。本人對sqlserver比較熟一些,故以sqlserver為列 set conn server.createobject adodb.connection conn.open server ip位址 pro...