匯出資料庫中的所有表的結構

2021-06-18 06:31:08 字數 3732 閱讀 3373

使用下面的儲存過程: 

如果輸入表名則取出此表,如果不輸入表名則選出全表結構,有問題請繼續問我。

--此儲存過程可以取出所輸入表的字段資訊,如果表名為空則列出當前資料庫中的所有表的資訊,

--如果@withview引數不為0則列出檢視的字段資訊,為0則不列檢視資訊

create

procedure

[dbo

].[table_info

](@tablename

varchar(50),@withview

bit=

0)

asbegin

ifnot

exists (select

*from dbo.sysobjects

where id =

object_id(n'

[dbo].[datadict]

') and

objectproperty(id, n'

isusertable

')=1)

begin

if@tablename

isnull

begin

if@withview

=0

begin

select

case o.type when'v

'then

'檢視:

'+ o.name else

'表:

'+ o.name end

as 表名,

c.name as 列名, t.name as 型別, c.length as 長度, c.prec as 精度,

c.scale as 小數字數,

case c.isnullable when

0then

'yes

'else

'no

'end

as 可否為空

from sys.syscolumns as c inner

join

sys.systypes as t on c.xusertype = t.xusertype inner

join

sys.sysobjects as o on c.id = o.id

where (o.type ='u

') and (o.name not

in ('

sysconstraints

', '

syssegments

')) order

by o.type, o.name, 列名

endelse

begin

select 表名=

case o.type when'v

'then

'檢視:

'+ o.name else

'表:

'+ o.name end

,c.name as 列名,t.name as 型別,c.length as 長度,c.prec 精度,c.scale as 小數字數 ,

可否為空=

case c.isnullable

when

0

then

'yes

'else

'no

'end

from syscolumns c,sysobjects o ,systypes t

where t.xusertype=c.xusertype and

o.id=c.id and (o.type='u

'or o.type='v

') and o.name not

in ( '

sysconstraints

', '

syssegments

') order

by o.type,o.name,c.name

endendelse

begin

select c.name as 列名, t.name as 型別, c.length as 長度, c.prec as 精度,

c.scale as 小數字數,

case c.isnullable when

0then

'yes

'else

'no

'end

as 可否為空

from sys.syscolumns as c inner

join

sys.systypes as t on c.xusertype = t.xusertype inner

join

sys.sysobjects as o on c.id = o.id

where (o.name =

@tablename)

order

by o.type, o.name, 列名

endend

else

begin

ifnot

@tablename

isnull

begin

select

@tablename

as 表名, a.name as 列名,c.explain as 說明, b.name as 資料型別,

a.length as 長度,a.xprec as 精度,a.xscale as 小數字數

from syscolumns a join systypes as b on b.xtype=a.xtype right

join datadict as c on c.fields=a.name

where id =

object_id(@tablename)

and c.tablename=

@tablename

order

by a.name

endelse

begin

select 表名=

case o.type when'v

'then

'檢視:

'+ o.name else

'表:

'+ o.name end

, a.name as 列名,c.explain as 說明, b.name as 資料型別,

a.length as 長度,a.xprec as 精度,a.xscale as 小數字數

from syscolumns a join systypes as b on b.xusertype=a.xusertype right

join datadict as c on c.fields=a.name right

join sysobjects as o on c.tablename=o.name

where a.id = o.id

and (o.type='u

'or o.type='v

') and o.name not

in ( '

sysconstraints

', '

syssegments

') order

by o.type, o.name,a.name

endendend

匯出資料庫中的所有表的結構

使用下面的儲存過程 如果輸入表名則取出此表,如果不輸入表名則選出全表結構,有問題請繼續問我。此儲存過程可以取出所輸入表的字段資訊,如果表名為空則列出當前資料庫中的所有表的資訊,如果 withview引數不為0則列出檢視的字段資訊,為0則不列檢視資訊 create procedure dbo tabl...

匯出資料庫表的結構與資料

注意是在登出資料庫後再執行 命令列下具體用法如下 mysqldump u使用者名稱 p密碼 d 資料庫名 表名 指令碼名 1 匯出資料庫為dbname的表結構 其中使用者名為root,密碼為dbpasswd,生成的指令碼名為db.sql mysqldump uroot pdbpasswd d dbn...

oracle資料庫表結構匯出

今天有同事打 要求要把oracle庫里的一張表的定義匯出個sql檔案,當時的第一反應就是要教他用exp imp來獲得表結構定義檔案,在 裡面說了半天還是沒能教會他,只好跑了一趟機房。路上就在想,oracle真是討厭,為什麼不在企業管理器裡直接加上個表結構匯出的選項,還要害我這麼跑一趟,真是 問了下要...