EXEC master..xp_cmdshell 'bcp ptdata.dbo.tb_users out e:/temp2.xls -c -q -S"WWW-75AF6DAC011" -U"sa" -P"y_ht_1987#"' --这样子是导出整张表
EXEC master..xp_cmdshell 'BCP "SELECT usnikname FROM tb_users" queryout e:/temp2.xls -c -U"sa" -P"y_ht_1987#"' --有选择性的导出数据
--同理导出到记事本(txt):如下
EXEC master..xp_cmdshell 'bcp ptdata.dbo.tb_users out e:/temp2.txt -c -q -S"WWW-75AF6DAC011" -U"sa" -P"y_ht_1987#"' --这样子是导出整张表
EXEC master..xp_cmdshell 'BCP "SELECT usnikname FROM tb_users" queryout e:/temp2.txt -c -U"sa" -P"y_ht_1987#"' --有选择性的导出数据
本文介绍了如何使用 SQL Server 的 xp_cmdshell 存储过程配合 BCP 命令来导出数据库表中的数据到 Excel 或纯文本文件。具体包括整表导出及选择性导出的方法,并提供了具体的 T-SQL 示例。
180

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



