儲存過程實現資料匯入匯出(SQL Server)
引自:http://community.csdn.net/Expert/topic/3717/3717728.xml?temp=.3920404
CREATE procedure File2Table
@servername varchar(200),
@username varchar(200),
@password varchar(200),
@tbname varchar(500),
@filename varchar(1000),
@isout bit
as
declare @sql varchar(8000)
if @tbname like '%.%.%'
begin
set @sql='master..xp_cmdshell ''bcp '[email protected]+' '+case when @isout=1 then 'out' else 'in' end+' "'[email protected]+'" -w -S "'[email protected]+'" -U "'[email protected]+'" -P"'[email protected]+'"'''
select @sql
exec(@sql)
end
執行
exec File2Table @servername='MYTOMATO',@username='sa',@password='',@tbname='pubs.dbo.employee',@filename='c:/zx.txt',@isout='1'
結果顯示:
master..xp_cmdshell 'bcp pubs.dbo.employee out "c:/zx.txt" -w -S "127.0.0.1" -U "sa" -P"000000"'
NULL
開始複製...
NULL
已複製了 43 行。
資料包的大小(位元組): 4096
時鐘時間(毫秒): 共 94
NULL
