匯出表結構

2021-09-25 18:38:56 字數 1390 閱讀 1893

資料庫遷移時,匯出表結構,用設計工具匯入

1、

select  

欄位名=a.name,

名稱=a.name,

型別=case when b.name='int' then '整數' when b.name='ntext' then '文字'when b.name='date' then '日期'

when b.name='smalldatetime' then '日期'when b.name='bigint' then '長整型'else'字元' end,

長度=columnproperty(a.id,a.name,'precision'),

允許空='',--case when a.isnullable=1 then '√'else '' end,

預設值=isnull(e.text,''),

字段說明=isnull(g.[value],'') ,

b.name,

主鍵=case when exists(select 1 from sysobjects where xtype='pk' and name in (

select name from sysindexes where indid in(

select indid from sysindexkeys where id = a.id and colid=a.colid

))) then '√' else '' end,

標識=case when columnproperty(a.id,a.name,'isidentity')=1 then '√'else '' end

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 sys.extended_properties g on a.id=g.major_id and a.colid=g.minor_id

left join sys.extended_properties f on d.id=f.major_id and f.minor_id =0

where d.name='cms_channels' --如果只查詢指定表,加上此條件

order by a.id,a.colorder

結果如下

2、匯入

匯出表結構

select 表名 case when a.colorder 1 then d.name else end,字段序號 a.colorder,欄位名 a.name,字段說明 isnull g.value 型別 b.name,占用位元組數 a.length,長度 columnproperty a.id,...

匯出表結構

select 欄位名 c.name,字段說明 isnull pfd.value n 型別 t.name,長度 c.max length,預設值 isnull d.definition,n 允許空 case when c.is nullable 1 then n else n end,isnull i...

Oracle 匯出表結構

分析oracle下匯出某使用者所有表的方法 可能很多使用oracle的客戶都會遇到想把某使用者所有表匯出的情況,本文就提供這樣乙個方法幫你輕鬆解決這個問題。首先在sqlplus下以該使用者登入到oracle資料庫,然後將以下內容貼上到sqlplus中 set feedback off set pag...