SQL server 将数据导出到文件方法

来源:互联网 发布:mysql怎么卸载干净 编辑:程序博客网 时间:2024/06/05 07:20

这里使用xp_cmdshell命令。Mark一下。

注:如果操作SQL Server的用户没有SP_configure的使用权限,需要将对应用户添加"sysadmin"角色。

1、首先启动该命令,方法如下:

SP_CONFIGURE'show advanced options',1
RECONFIGURE

SP_CONFIGURE 'xp_cmdshell',1
RECONFIGURE

2、将整个表数据导出到文件,方法如下:

exec master..xp_cmdshell ' bcp database.table out  d:/data.csv -c -t -T '


3、将查询结果导出到文件,方法如下:


 exec master..xp_cmdshell ' bcp "select * from test..PAD6_holding_s where TradingDay = convert(varchar(19),GETDATE(),101)" queryout "D:/text.csv" /c -U test_pan -P 123abc'
 
 

阅读全文
0 0
原创粉丝点击