先开启服务器配置选项:
EXEC sp_configure 'show advanced options', 1
RECONFIGURE
EXEC sp_configure 'xp_cmdshell', 1
RECONFIGURE
/** 导出文本文件
EXEC master..xp_cmdshell 'bcp dbname..tablename out c:/DT.txt -c -S servername -U sa -P password'
或
EXEC master..xp_cmdshell 'bcp "Select * from dbname..tablename" queryout c:/DT.txt -c -S servername -U sa -P password'
导出到TXT文本,用逗号分开
exec master..xp_cmdshell 'bcp "库名..表名" out "d:/tt.txt" -c -t ,-U sa -P password'
BULK INSERT 库名..表名
FROM 'c:/test.txt'
WITH (
FIELDTERMINATOR = ';',
ROWTERMINATOR = '/n'
)