一、sql server 和access的數據導入導出
常規的數據導入導出:使用dts向導遷移你的access數據到sql server,你可以使用這些步驟:
1在sql server企業管理器中的tools(工具)菜單上,選擇data transformation
2services(數據轉換服務),然后選擇 czdimport data(導入數據)。
3在choose a data source(選擇數據源)對話框中選擇microsoft access as the source,然后鍵入你的。mdb數據庫(。mdb文件擴展名)的文件名或通過瀏覽尋找該文件。
4在choose a destination(選擇目標)對話框中,選擇microsoft ole db prov ider for sql server,選擇數據庫服務器,然后單擊必要的驗證方式。
5在specify table copy(指定表格復制)或query(查詢)對話框中,單擊copy tables(復制表格)。
6在select source tables(選擇源表格)對話框中,單擊select all(全部選定)。下一步,完成。
transact-sql語句進行導入導出:
1.在sql server里查詢access數據:
select * from opendatasource( ///////////////'microsoft.jet.oledb.4.0///////////////',///////////////'data source="c:////////////////db.mdb";user id=admin;password=///////////////')……表名
2.將access導入sql server在sql server 里運行:
3.將sql server表里的數據插入到access表中在sql server 里運行:
實例:insert into openrowset(///////////////'microsoft.jet.oledb.4.0///////////////',///////////////'c:////////////////db.mdb///////////////';///////////////'admin///////////////';///////////////'///////////////', test) select id,name from test
insert into openrowset(///////////////'microsoft.jet.oledb.4.0///////////////', ///////////////'c:////////////////trade.mdb///////////////'; ///////////////'admin///////////////'; ///////////////'///////////////', 表名) select * from sqltablename
二、sql server 和excel的數據導入導出
1、在sql server里查詢excel數據:
下面是個查詢的示例,它通過用于 jet 的 ole db 提供程序查詢 excel 電子表格。
select * from opendatasource ( ///////////////'microsoft.jet.oledb.4.0///////////////',///////////////'data source="c:////////////////finance////////////////account.xls";user id=admin;password=;extended properties=excel 5.0///////////////')……xactions
2、將excel的數據導入sql server :
實例:select * into newtable from opendatasource( ///////////////'microsoft.jet.oledb.4.0///////////////',///////////////'data source="c:////////////////finance////////////////account.xls";user id=admin;password=;extended properties=excel 5.0///////////////')……xactions
3、將sql server中查詢到的數據導成一個excel文件t-sql代碼:
實例:exec master……xp_cmdshell ///////////////'bcp saletesttmp.dbo.cusaccount out c:////////////////temp1.xls -c -q -s"pmserver" -u"sa" -p"sa"http:///////////////'
exec master……xp_cmdshell ///////////////'bcp "select au_fname, au_lname from pubs……authors order by au_lname" queryout c://////////////// authors.xls -c -sservername -usa -ppassword///////////////'
4、在sql server里往excel插入數據:
t-sql代碼:insert into opendatasource(///////////////'microsoft.jet.oledb.4.0///////////////',///////////////'extended properties=excel 8.0;data source=c:////////////////training////////////////inventur.xls///////////////')……[filiale1$] (bestand, produkt) values (20, ///////////////'test///////////////')
總結:利用以上語句,我們可以方便地將sql server、access和excel電子表格軟件中的數據進行轉換,為我們提供了極大方便!
新聞熱點
疑難解答