27,579
社区成员
发帖
与我相关
我的任务
分享
USE CSDN
GO
CREATE TABLE [dbo].[AutoIdentity]
(
[ID] [int] IDENTITY(1,1) NOT NULL,
[NAME] [nvarchar](255) NULL
)
GO
INSERT INTO dbo.[AutoIdentity] (name)
SELECT 'name1' UNION ALL
SELECT 'name2' UNION ALL
SELECT 'name3'
GO
--打开开关
sp_configure 'xp_cmdshell', 1;
go
reconfigure;
GO
--BCP导出1
EXEC master..xp_cmdshell
'bcp CSDN.dbo.AutoIdentity out c:\currency1.txt -c -U"sa" -P"1q2w3e4R"'
--BCP导出2
EXEC master..xp_cmdshell
'bcp "select * from CSDN.dbo.AutoIdentity" queryout queryout "c:\currency1.txt" /c -S"实例名" -U"sa" -P"1q2w3e4R"'
go
--关闭开关
sp_configure 'xp_cmdshell', 0;
go
reconfigure;
GO
-- 启用xp_cmdshell选项
exec sp_configure 'xp_cmdshell', 1
reconfigure
-- bcp导出txt
exec master..xp_cmdshell 'bcp "select * from [user]" queryout D:\user.txt -S "[服务器名]" -U "[帐号]" -P "[密码]" -c '
EXEC master..xp_cmdshell 'bcp "SELECT * FROM [table]" queryout "d:\table.txt" -c -t \t -S"127.0.0.1" -U"sa" -P"123456" '
将表名、数据库的IP地址、密码换成你的就OK了