在不一樣平臺上導數據時,只能用BCP命令,可是BCP命令不能導出數據庫表結構,因此需進行數據庫表結構的導出。
在sybase12.5版本以上,能夠用以下方式導出表結構:
ddlgen –Usa –Pxxx –Ddb_name –Sxxx:port –Ooutput_file
其中db_name指所要導出的數據庫名。sql
低於sybase12.5版本的,得進行執行腳本的方式導出表結構。腳本文件內容以下:
use sybsystemprocs
go數據庫
if object_id('dbo.sp_ddl_create_table') is not null
drop procedure sp_ddl_create_table
print "Dropping sp_ddl_create_table"
goide
create proc sp_ddl_create_table
asspa
-- Creates the DDL for all the user tables in the
-- current databaseip
select right('create table ' + so1.name + '(' + '
', 255 * ( abs( sign(sc1.colid - 1) - 1 ) ) )+
sc1.name + ' ' +
st1.name + ' ' +
substring( '(' + rtrim( convert( char, sc1.length ) ) + ') ', 1,
patindex('%char', st1.name ) * 10 ) +
substring( '(' + rtrim( convert( char, sc1.prec ) ) + ', ' + rtrim(
convert( char, sc1.scale ) ) + ') ' , 1, patindex('numeric', st1.name ) * 10 ) +
substring( 'NOT NULL', ( convert( int, convert( bit,( sc1.status & 8 ) ) ) * 4 ) + 1,
8 * abs(convert(bit, (sc1.status & 0x80)) - 1 ) ) +
right('identity ', 9 * convert(bit, (sc1.status & 0x80)) ) +
right(',', 5 * ( convert(int,sc2.colid) - convert(int,sc1.colid) ) ) +
right(' )
' + 'go' + '
' + '
', 255 * abs( sign( ( convert(int,sc2.colid) - convert(int,sc1.colid) ) ) -
1 ) )
from sysobjects so1,
syscolumns sc1,
syscolumns sc2,
systypes st1
where so1.type = 'U'
and sc1.id = so1.id
and st1.usertype = sc1.usertype
and sc2.id = sc1.id
and sc2.colid = (select max(colid)
from syscolumns
where id = sc1.id)
order by so1.name, sc1.colid
gostring
if object_id('dbo.sp_ddl_create_table') is not null
begin
grant execute on sp_ddl_create_table to public
print "Created sp_ddl_create_table"
end
else
print "Failed to create sp_ddl_create_table"
go
查看具體某數據庫表結構方法以下,以查看nbcredit數據庫表結構爲例:
編輯腳本文件script.txt,保存在c:,內容以下:
use nbcredit
go
sp_ddl_create_table
go
而後執行如下語名:isql –Usa –Pxxx –b –i script.txt –o scriptout.txt
其中scriptout.txt文件的內容即爲整個數據庫表結構。it