SQLSERVER 导入\导出sql文件

版权声明: https://blog.csdn.net/ClearLoveQ/article/details/83062480

1.EXEC master..xp_cmdshell 'bcp test.dbo.P_Aspect in c:\temp1.txt -c -q -S"servername" -U"sa" -P""'
//导入 

EXEC master..xp_cmdshell 'bcp test.dbo.P_Aspect out c:\temp1.txt -c -q -S"servername" -U"sa" -P""'
//导出

在导出时如果报错:SQL Server阻止了对组件‘xp_cmdshell’的过程‘sys.xp_cmdshell’的访问
解决办法:
要想以文本的方式输出查询结果,首先需要:
通过查询分析器,选择Master数据库,然后执行以下SQL内容:
sp_configure 'show advanced options',1      --1代表允许,0代表阻止
reconfigure
go
sp_configure 'xp_cmdshell',1
reconfigure
go

然后再执行上面的导出语句

2.执行sql文件
C:\>sqlcmd -i  test.sql -d databasename -s 127.0.0.1
注意:这个test.sql文件要放到对应的盘符中去(这里就是放入C盘)

猜你喜欢

转载自blog.csdn.net/ClearLoveQ/article/details/83062480