天天被操天天被操综合网,亚洲黄色一区二区三区性色,国产成人精品日本亚洲11,欧美zozo另类特级,www.黄片视频在线播放,啪啪网站永久免费看,特别一级a免费大片视频网站

現(xiàn)在位置:范文先生網(wǎng)>理工論文>計(jì)算機(jī)論文>Foxpro DBF數(shù)據(jù)庫轉(zhuǎn)換成SQL Server 6.5表的幾種方法

Foxpro DBF數(shù)據(jù)庫轉(zhuǎn)換成SQL Server 6.5表的幾種方法

時(shí)間:2023-02-20 22:51:05 計(jì)算機(jī)論文 我要投稿
  • 相關(guān)推薦

Foxpro DBF數(shù)據(jù)庫轉(zhuǎn)換成SQL Server 6.5表的幾種方法

   摘要:本文主要介紹用SQL Server bcp、Foxpro編程、Access等方法將.dbf數(shù)據(jù)庫轉(zhuǎn)換到SQL Server表的方法。

關(guān)鍵詞:Xbase DBF SQL Server 數(shù)據(jù)庫 轉(zhuǎn)換

1、前言

當(dāng)今,數(shù)據(jù)庫聯(lián)網(wǎng)實(shí)現(xiàn)數(shù)據(jù)共享已經(jīng)成為信息系統(tǒng)建設(shè)中一個(gè)迅速發(fā)展的潮流。利用SQL Server、Oracal、Sybase等客戶機(jī)/服務(wù)器(Client/Server)體系結(jié)構(gòu)的數(shù)據(jù)庫系統(tǒng)進(jìn)行信息系統(tǒng)的開發(fā)、更新改造已成為當(dāng)前一大趨勢(shì)。而Dbase、Foxbase、Foxpro是我國近年應(yīng)用較為廣泛的數(shù)據(jù)庫開發(fā)軟件,許多單位、部門多年來積累了大量的寶貴的數(shù)據(jù)資料,這些部門在進(jìn)行計(jì)算機(jī)信息系統(tǒng)改造、更新的同時(shí),面臨如何繼承大量歷史數(shù)據(jù)的問題,本文介紹三種將DBF數(shù)據(jù)轉(zhuǎn)換成SQL Server表的方法。

2、利用SQL Server所提供的塊拷貝實(shí)用程序(bcp)轉(zhuǎn)換

實(shí)用程序bcp.exe可從服務(wù)器SQL目錄下的BINN子目錄下獲得。

2.1、bcp的 命令格式及主要參數(shù)

bcp [[database_name.]owner.] table_name {in|out} datafile [/m maxerror ][/f formatfile] [/e errfile] [/n] [/c] [/t] field_term] [/r row_term] [/U login_ID] [/P password] [/S servername] [/v version] [/a packet_size]
主要參數(shù):
database_name    數(shù)據(jù)庫名
in|out        in從文件到數(shù)據(jù)庫表的拷貝。
            out從數(shù)據(jù)庫表到文件拷貝。
datafile         操作系統(tǒng)文件的路徑。該路徑的長(zhǎng)度可以是
1-255個(gè)字符。也可指明磁盤驅(qū)動(dòng)器名字。
/C             用字符類型作為缺省值執(zhí)行拷貝操作。
/u login_ID    指定登錄標(biāo)識(shí)符。
/P password    允許指定一個(gè)口令。
/S servername    允許用戶指定連接到哪個(gè)SQL Server

2.2、實(shí)現(xiàn)轉(zhuǎn)換的具體方法

我們以Foxpro的數(shù)據(jù)庫結(jié)構(gòu)的單位職工庫(zg.dbf)為例,進(jìn)行數(shù)據(jù)轉(zhuǎn)換。其數(shù)據(jù)結(jié)構(gòu)為:

字段名 類型 字段長(zhǎng)度 小數(shù)點(diǎn)位數(shù) 字段內(nèi)容
bh C 4 職工編號(hào)
xm C 8 職工姓名
xb C 2 性別
nl N 2 0 年齡
zw C 10 職務(wù)
gzsj D 參加工作時(shí)間
jl M 簡(jiǎn)歷
zp G 照片

實(shí)現(xiàn)步驟:

(1)、啟動(dòng)服務(wù)器,進(jìn)入Window NT,SQL Server 6.0,打開SQL Enterprise Manager為單位職工庫創(chuàng)建一個(gè)數(shù)據(jù)庫設(shè)備zg.dat,然后在該設(shè)備上建立zg數(shù)據(jù)庫及表(Table),表的數(shù)據(jù)結(jié)構(gòu)要與zg.dbf的數(shù)據(jù)結(jié)構(gòu)一致;蛴靡韵耂QL Server命令創(chuàng)建設(shè)備和創(chuàng)建表。

A、創(chuàng)建數(shù)據(jù)設(shè)備
disk init
name='zg'                     數(shù)據(jù)庫設(shè)備名
physname='c:\\zg\\zg.dat'    數(shù)據(jù)庫文件所在路徑
vdevno=8                     數(shù)據(jù)庫設(shè)備的標(biāo)識(shí)號(hào)
size=5120                     數(shù)據(jù)庫設(shè)備大小(10M)

B、建立zg表
create database zg_data on zg=1024,log on zg=1024     建立數(shù)據(jù)庫
use zg_data
create table zg ( bh char (4) null, xm char (8) null, xb char (2) null, nl int null, zw char (10) null,gzsj datatime null, jl text null, zp image null ) 建立表
go

(2)、在客戶機(jī)上啟動(dòng)Foxpro,用USE命令打開需轉(zhuǎn)換的.dbf文件,用COPY命令將.dbf文件中數(shù)據(jù)轉(zhuǎn)換成標(biāo)準(zhǔn)的文本文件.txt,命令如下:
use zg.dbf
copy all to zg.txt deli with blan

(3)、從客戶機(jī)登錄到Windows NT服務(wù)器上,將zg.txt文件拷貝到服務(wù)器的職工庫目錄c:\\zg下。

(4)、在服務(wù)器上,由Windows NT進(jìn)入到MS-DOS狀態(tài),然后執(zhí)行bcp將數(shù)據(jù)從zg.txt轉(zhuǎn)換到SQL表,命令格式如下:

bcp zg in zg.txt /c /s mainserver /u manager /P 0001 (mainserver為服務(wù)器名,manager為用戶名,0001為用戶口令)。

該轉(zhuǎn)換方法速度較快,不占用服務(wù)器上事務(wù)日志空間。但較為復(fù)雜、繁鎖,操作者必須熟練掌握Foxpro、SQL Server的命令和操作,而且無法將Foxpro的Memo、General字段轉(zhuǎn)換到SQL Ser

ver表。

3、用Foxpro for Window 2.5 編程實(shí)現(xiàn)轉(zhuǎn)換

"用Foxpro編程實(shí)現(xiàn)數(shù)據(jù)轉(zhuǎn)換"即通過SQL Server提供的ODBC接口(開放數(shù)據(jù)庫接口)及Foxpr提供ODBC接口工具Connectivity Kit (fpsql.fll),建立SQL與Foxpro的連接,由Foxpro向SQL Server提交創(chuàng)建表命令,然后將.dbf的每條記錄,串成一個(gè)字符串,將插入命令連同字符串提交給SQL Server,完成數(shù)據(jù)轉(zhuǎn)換。
實(shí)現(xiàn)步驟:

(1)、ODBC的設(shè)置:在客戶機(jī)上啟動(dòng)Windows for group,進(jìn)入Windows的控制面板( Control panel )。雙擊ODBC圖標(biāo),進(jìn)行zg數(shù)據(jù)庫的ODBC驅(qū)動(dòng)設(shè)置。

選擇"Add"增加新的ODBC驅(qū)動(dòng)接口,在Install ODBC drivers項(xiàng)選擇"SQL Server",按"OK",彈出"ODBC SQL Server Setup"窗口,在 Data source name項(xiàng)中輸入"zg_data",Server項(xiàng)輸入"mainserver",按"OK"完成設(shè)置。

(2)、采用上述方法一中步驟1的⑴、⑵創(chuàng)建zg數(shù)據(jù)庫設(shè)備及數(shù)據(jù)庫,然后執(zhí)行Foxpro程序crea_table,創(chuàng)建一個(gè)結(jié)構(gòu)與.dbf結(jié)構(gòu)相同的SQL Server表。程序清單如下:

crea_table.prg 程序清單

set talk off
close all
clear all
clear
store "" to dbf_name    
&& dbf_name 待轉(zhuǎn)換的.dbf數(shù)據(jù)庫
store "" to sql_db
&& sql_db目的SQL數(shù)據(jù)庫
store "" to sql_com    
&& sql_com向SQL Server提交的命令
store "" to sql_title    
&& sql_title 為向SQL Server提交命令字頭
store 0 to handle        
&& handle 為Foxpro與SQL Server連接的標(biāo)識(shí)
store 0 to success    
&& success為命令提交成功與否的標(biāo)識(shí)
set libr to fpsql.fll
@2,20 say "請(qǐng)輸入要轉(zhuǎn)換的數(shù)據(jù)庫(dbf)名:" get dbf_name
@3,20 say "請(qǐng)輸入目的SQL數(shù)據(jù)庫名:" get sql_db
read
dbf_name=allt(dbf_name)
sql_db=allt(sql_db)
handle=dbconnect(sql_db, "sa","")    
&& 建立Foxpro與SQL Server連接
if handle>0    && 若連接成功則
use &dbf_name as op_dbf in 0
&&以op_dbf為別名打開待轉(zhuǎn)換數(shù)據(jù)庫
sele op_dbf
copy to db_stru stru exte
&& 將其數(shù)據(jù)結(jié)構(gòu)拷貝生成db_stru庫
use db_stru in 0
sele db_stru
goto top
sql_com="creat table "+dbf_name+"( "
do while .not. eof()
sql_com=sql_com+field_name+" "
do case
case field_type="C"
sql_com=sql_com+"char ("+;
allt(str(field_len))+ ")"
case field_type="N"
if field_dec=0
if field_len<8
sql_com=sql_com+"int "
else
sql_com=aql_com+"float "
endif
else
        sql_com=sql_com+"float "
endif
case field_type="D"
sql_com=sql_com+"datatime "
case field_type="M"
sql_com=sql_com+"text "
case field_type="G"
sql_com=sql_com+"binary "
endcase
skip
if .not.eof()
sql_com=sql_com+","
endif
enddo
sql_com=aql_com+" )"
success=dbexec(handle,sql_com)
if success
wait wind "SQL Server表已建立成功! "
else
wait wind "SQL Server表建立失敗! "
endif
close all
clear all
retu
else    && 若連接不成功
wait wind "對(duì)不起,輸入?yún)?shù)錯(cuò)誤,無法連接SQL Server'
clear read
retu    
endif

(3)、再執(zhí)行Foxpro程序conv_data將數(shù)據(jù)由.dbf傳輸?shù)絊QL Server表中。

conv_data.prg 程序清單

conv_data.prg 程序清單
set talk off
close all
clear all
clear
store "" to dbf_name    
&&dbf_name待轉(zhuǎn)換的.dbf數(shù)據(jù)庫
store "" to sql_db    
&

&sql_db目的SQL數(shù)據(jù)庫
store "" to sql_com    
&&sql_com向SQL Server提交的命令
store "" to fname        
&&fname字段名
store 0 to handle        
&&handle Foxpro與SQL Server連接的標(biāo)識(shí)
store 0 to success    
&&success命令提交成功與否的標(biāo)識(shí)
set libr to fpsql.fll
@2,20 say "請(qǐng)輸入要轉(zhuǎn)換的數(shù)據(jù)庫(dbf)名:" get dbf_name
@3,20 say "請(qǐng)輸入目的SQL數(shù)據(jù)庫名:" get sql_db
read
dbf_name=allt(dbf_name)
sql_db=allt(sql_db)
handle=dbconnect(sql_db, "sa","")
&&建立Foxpro與SQL Server連接
if handle>0    && 若連接成功則
use &dbf_name as op_dbf in 0
&&以op_dbf為別名打開待轉(zhuǎn)換數(shù)據(jù)庫
sele op_dbf
copy to db_stru stru exte
&&將其數(shù)據(jù)結(jié)構(gòu)拷貝生成db_stru庫
use db_stru in 0
sele db_stru
goto top
sql_title="insert into "+dbf_name+" ( "
do while .not.eof()
sql_title=sql_title+field_name
skip
if .not.eof()
    sql_title=sql_title+","
else
    sql_title=sql_title+" ) values ('"
endif
enddo
sele op_dbf
goto top
do while .not.eof()
sql_com=sql_title
sele db_stru
goto top
do while .not.eof()
    fname=field_name
    do case
    case field_type="C"
        sql_com=sql_com+&fname
    case field_type="N"
        sql_com=sql_com+"convert(int(8),'"+str(*fname)+"')"
    case field_type="M"
        sql_com=sql_com+'null'
    case field_type="G"
        sql_com=sql_com+'null'
    endcase
    skip
    if .not.eof()
    sql_com=sql_com+"','"
    else
    sql_com=aql_com+"')"
    endif
enddo
success=dbexec(handle,sql_com)
sele op_dbf
skip
enddo
else    && 若連接不成功
wait wind "對(duì)不起,輸入?yún)?shù)錯(cuò)誤,無法連接SQL Server"
clear read
retu    
endif

使用上述方法,只要知道一些簡(jiǎn)單的SQL Server操作及Foxpro編程便可實(shí)現(xiàn)將.dbf數(shù)據(jù)轉(zhuǎn)換到SQL Server。運(yùn)行程序然后輸入待轉(zhuǎn)換的數(shù)據(jù)庫名,及目的數(shù)據(jù)庫名就可實(shí)現(xiàn)轉(zhuǎn)換,快捷方便。但不足的是,該方法在原數(shù)據(jù)庫.dbf含有Memo、General字段時(shí),轉(zhuǎn)換就比較困難,目前尚沒有找到有效的解決方法。

4、用第三方數(shù)據(jù)庫軟件Access進(jìn)行轉(zhuǎn)換

Access是Microsoft公司的數(shù)據(jù)庫開發(fā)軟件,使用Access提供的數(shù)據(jù)輸入(Inport)/輸出(Export)的功能及ODBC接口,可直接將數(shù)據(jù)結(jié)構(gòu)及數(shù)據(jù)轉(zhuǎn)送到SQL Server。
實(shí)現(xiàn)步驟:

(1)、按方法二中的第1、2步驟完成數(shù)據(jù)庫設(shè)備、數(shù)據(jù)庫創(chuàng)建和ODBC接口的設(shè)置。

(2)、然后在Windows for Workgroup中啟動(dòng)Access,在File菜單中選擇"new"創(chuàng)建一個(gè)新的Access數(shù)據(jù)庫,然后在File菜單中選擇"Attach table"連接zg.dbf數(shù)據(jù)庫。

(3)、在"Attach"窗口的"Data source"欄中選擇數(shù)據(jù)庫源為Foxpro 2.5,按"OK",之后彈出"Select Microsoft Access Database"窗口,在該窗口選擇要轉(zhuǎn)換的.dbf數(shù)據(jù)庫zg.dbf,按"OK"結(jié)束,然后按"Close"完成數(shù)據(jù)庫連接。

(4)、在File菜單中選擇"

Export"輸出數(shù)據(jù),在"Export"窗口選擇目標(biāo)數(shù)據(jù)庫類型"<SQL Server>"按"OK"進(jìn)入下一窗口"Select Microsoft Access Object",在"Object in DB1"欄選擇要轉(zhuǎn)換的數(shù)據(jù)庫zg, 在窗口的"View"欄下選擇"Table"項(xiàng),,按"OK"。

(5)、進(jìn)入"Export"窗口,在"Export zg to"欄目下輸入目的數(shù)據(jù)庫名zg,按"OK"。進(jìn)入"SQL Data Sources"窗口,在"Select Data Source",選擇在ODBC中定義好的zg數(shù)據(jù)源,按"OK"

(6)、進(jìn)入"SQL Server login"窗口,在"Login ID:"欄中輸入登錄用戶名"sa",在"Password"欄中若有登錄口令則輸入口令。否則按"OK"開始進(jìn)行數(shù)據(jù)轉(zhuǎn)換。

使用該方法用戶不需要深入了解Foxpro命令及SQL Server命令,也不須深入了解Access操作,更不需對(duì).dbf數(shù)據(jù)庫的數(shù)據(jù)結(jié)構(gòu)進(jìn)行分析,Access可根據(jù)原.dbf數(shù)據(jù)庫的結(jié)構(gòu)自動(dòng)在SQL Server上創(chuàng)建一個(gè)結(jié)構(gòu)相同的表,并且可將原.dbf數(shù)據(jù)庫中不論是字符型、數(shù)字型、日期型、Memo型、General型的所有數(shù)據(jù)轉(zhuǎn)換到SQL Server表中。該方法可以簡(jiǎn)單、方便快捷、完整地將所有.dbf中的數(shù)據(jù)的轉(zhuǎn)換到SQL Server。

但使用該方法要注意一點(diǎn),若要轉(zhuǎn)換的數(shù)據(jù)量很大時(shí),SQL Server中分配給該數(shù)據(jù)庫的日志設(shè)備要足夠大,或可在SQL Server中的ISQL/w命令窗口中用以下命令進(jìn)行監(jiān)控,并及時(shí)清除。

dbcc sqlperf (logspace) 檢查事務(wù)日志空間的使用量
dump transaction zg with truncate_only 清除事務(wù)日志中已完成任務(wù)的數(shù)據(jù)

5、結(jié)束語

以上三種方法運(yùn)行環(huán)境服務(wù)器端網(wǎng)絡(luò)操作系統(tǒng)為Window NT 4.0,網(wǎng)絡(luò)數(shù)據(jù)庫為SQL Server 6.5,客戶機(jī)Windows 95,F(xiàn)oxpro for Window 2.6,Access 97。

方法二、方法三均通過ODBC數(shù)據(jù)接口進(jìn)行數(shù)據(jù)轉(zhuǎn)換。因此,這兩種方法對(duì)Oracal、Sybase等數(shù)據(jù)庫也可適用,只要對(duì)Windows中的ODBC數(shù)據(jù)接口設(shè)置作些改動(dòng),我們也可將.dbf的數(shù)據(jù)轉(zhuǎn)換到Oracal或Sybase的表中。以此類推,只要數(shù)據(jù)庫提供了ODBC功能,使用上述方法二、方法三均可實(shí)現(xiàn)兩種數(shù)據(jù)庫之間的數(shù)據(jù)轉(zhuǎn)換。


【Foxpro DBF數(shù)據(jù)庫轉(zhuǎn)換成SQL Server 6.5表的幾種方法】相關(guān)文章:

SQL Server數(shù)據(jù)庫教學(xué)方法探索05-30

開發(fā)基于SQL SERVER 的C/S數(shù)據(jù)庫應(yīng)用系統(tǒng)?08-06

如何用VB存取SQL Server中的圖像數(shù)據(jù)04-12

SQL Server的七個(gè)問題及其解決辦法04-22

ASP開發(fā)Browse/Server模式的Web數(shù)據(jù)庫08-06

sql數(shù)據(jù)庫備份和恢復(fù)常用操作08-12

《Visual FoxPro6.0數(shù)據(jù)庫教程》課程改革及評(píng)價(jià)方案05-23

作文的幾種修改方法08-17

在應(yīng)用程序客戶端備份和恢復(fù)MSSQL SERVER數(shù)據(jù)庫的一種方法08-06