这里使用xp_cmdshell命令。Mark一下。
注:如果操作SQL Server的用户没有SP_configure的使用权限,需要将对应用户添加"sysadmin"角色。
1、首先启动该命令,方法如下:
SP_CONFIGURE'show advanced options',1RECONFIGURE
SP_CONFIGURE
'xp_cmdshell',1RECONFIGURE2、将整个表数据导出到文件,方法如下:
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'
本文介绍如何通过 SQL Server 中的 xp_cmdshell 命令启用及使用 bcp 工具来导出表数据和查询结果到 CSV 文件的方法。包括设置权限、启动 xp_cmdshell 以及具体的 bcp 命令用法。
1178

被折叠的 条评论
为什么被折叠?



