一、開啟另乙個資料庫
1.開啟sql server2000的另乙個資料庫的表
(1). select * from openrowset('sqloledb','sprogram';'develop';'11111','select * from kind')
(2). select * from openrowset('sqloledb','190.1.1.247';'develop';'11111','select * from kind')
(3). select * from opendatasource('sqloledb','data source=sprogram;user id=develop;password=11111').new_ks.dbo.kind
2.開啟access2000的乙個表
(1). select * from opendatasource( 'microsoft.jet.oledb.4.0','data source=e:/north.mdb;user id=admin;password=')...supply
(2). select * from openrowset('microsoft.jet.oledb.4.0',
'e:/north.mdb';'admin';'',supply)
(3). select * from openrowset('microsoft.jet.oledb.4.0',
'e:/north.mdb';'admin';'','select * from supply where **商編號》10')
3.開啟excel的乙個表
(1). select * from openrowset('microsoft.jet.oledb.4.0'
,'excel 5.0;hdr=yes;database=e:/test.xls',sheet1$)
(2). select * into 表 from openrowset('microsoft.jet.oledb.4.0'
,'excel 5.0;hdr=yes;database=e:/test1.xls',sheet3$)
二、匯入與匯出
1. 用bcp工具匯入匯出
(1)xls檔案
exec master..xp_cmdshell 'bcp "select class_no,kind_no,cn_name from new_ks.dbo.kind order by 1,2" queryout "e:/test3.xls" -c -q -s"sprogram" -u"develop" -p"12345"'
(2)/** 匯入文字檔案
--入sqlserver
select * into 你的表 from openrowset('msdasql', 'driver=;defaultdir=c:/temp;','select * from contact.txt')
--查詢匯出
exec master..xp_cmdshell 'bcp "select class_no,kind_no,cn_name from new_ks.dbo.kind order by 1,2" queryout "e:/tx1.txt" -c -q -s"sprogram" -u"develop" -p"12345"'
--直接匯出
exec master..xp_cmdshell 'bcp new_ks.dbo.class out "e:/tx3.txt" -c -s"sprogram" -u"develop" -p"12345"'
--直接匯入
exec master..xp_cmdshell 'bcp "資料庫.dbo.資料表" in c:/dt.txt -c -s伺服器名 -u使用者名稱 -p密碼'
exec master..xp_cmdshell 'bcp hdh.dbo.kind in "e:/tx1.txt" -c -q -s -u -p'
exec master..xp_cmdshell 'bcp hdh.dbo.kind in "e:/test3.xls" -c -q -s -u -p'
--用bulk insert匯入
bulk insert hdh.dbo.kind
from 'e:/tx1.txt'
with (
fieldterminator = '/t',
rowterminator = '/n'
)前提條件是表如kind要存在,而且欄位與test.txt欄位數目要一樣多
在查詢分析器中執行,而且是以sa使用者登入
bulk insert tbyhhk from 'c:/t.txt' with( formatfile='c:/bcp.txt')
3.其它資料庫匯入方法:
(1)--/* dbase iv檔案
select * from
openrowset('microsoft.jet.oledb.4.0'
,'dbase iv;hdr=no;imex=2;database=c:/','select * from [客戶資料4.dbf]')
--*/
(2)--/* dbase iii檔案
select * from
openrowset('microsoft.jet.oledb.4.0'
,'dbase iii;hdr=no;imex=2;database=c:/','select * from [客戶資料3.dbf]')
--*/
(3)--/* foxpro 資料庫
select * from openrowset('msdasql',
'driver=microsoft visual foxpro driver;sourcetype=dbf;sourcedb=c:/',
'select * from [aa.dbf]')
--*/
SQL語句匯入匯出大全
源 不管是把sql server表的資料插入excel insert into openrowset microsoft.jet.oledb.4.0 excel 5.0 hdr yes database c test.xls test select from t test 還是把excel的資料插入...
SQL Server SQL語句匯入匯出大全
匯出到excel exec master.xp cmdshell bcp settledb.dbo.shanghu out c temp1.xls c q s gnetdata gnetdata u sa p 匯入excel select from opendatasource microsoft....
SQL 匯出匯入大全 引
匯出到excel exec master.xp cmdshell bcp settledb.dbo.shanghu out c temp1.xls c q s gnetdata gnetdata u sa p 匯入excel select from opendatasource microsoft....