BCP批量匯入匯出

2022-02-05 06:13:18 字數 1056 閱讀 4359

1.批量匯入

bcp "select

*from dbname.dbo.tablename" queryout e:\test.sql -s . -u sa -p1 -

cexec master..xp_cmdshell '

bcp dbname.dbo.tablename in e:\test.sql -c -t

'

2.許可權配置

/*

mssql2005 如何啟用xp_cmdshell

預設情況下,sql server2005安裝完後,xp_cmdshell是禁用的(可能是安全考慮),如果要使用它,可按以下步驟

*/--

允許配置高階選項

exec sp_configure '

show advanced options

', 1

go--

重新配置

reconfigure

go--

啟用xp_cmdshell

exec sp_configure '

xp_cmdshell

', 1

go--

重新配置

reconfigure

go--

執行想要的xp_cmdshell語句

exec xp_cmdshell '

query user'go

--用完後,要記得將xp_cmdshell禁用(出於安全考慮)

--允許配置高階選項

exec sp_configure '

show advanced options

', 1

go--

重新配置

reconfigure

go--

禁用xp_cmdshell

exec sp_configure '

xp_cmdshell

', 0

go--

重新配置

reconfigure

go

bcp匯入匯出

匯出 set cmd n bcp select from 庫.dbo.test1 n queryout d voc txt c u liyuepeng p liyuepeng exec master.xp cmdshell cmd set cmd n bcp 庫.dbo.test2 n in d v...

BCP 高效批量匯入

將oledb讀取的excel資料快速插入的sqlserver中,很多人通過迴圈來拼接sql,這樣做不但容易出錯而且效率低下,最好的辦法是使用bcp,也就是system.data.sqlclient.sqlbulkcopy 類來實現。不但速度快,而且 簡單,下面測試 匯入乙個6萬多條資料的sheet,...

BCP匯入匯出MsSql

匯出資料到tset1.txt,並指定本地資料庫的使用者名稱和密碼 這裡需要指定資料庫完全限定名。username 資料登入名 password 資料庫密碼 exec master.xp cmdshell bcp select from testdb.dbo.testvoucher queryout ...