SQLserver单表数据导入导出

 1 EXEC sp_configure 'show advanced options', 1
 2 
 3 GO
 4 
 5 RECONFIGURE
 6 
 7 GO
 8 
 9 EXEC sp_configure 'xp_cmdshell', 1
10 
11 GO
12 
13 RECONFIGURE
14 
15 GO
16 //导出
17 EXEC userinfo..xp_cmdshell 'bcp userinfo.dbo.students out D:studentes.txt -c -T -U''sa'' -P''123456'''

  解释一下 导出

    userinfo:数据库名称

    students:表名

    D:students.txt:导出路径和导入文件名称和类型

    sa:用户名

    123456:密码

   导入

 1 //导入
 2 EXEC userinfo..xp_cmdshell 'bcp userinfo.dbo.students in D:studentes.txt -c -T -U''sa'' -P''123456'''
 3 
 4 EXEC sp_configure 'show advanced options', 1
 5 
 6 GO
 7 
 8 RECONFIGURE
 9 
10 GO
11 
12 EXEC sp_configure 'xp_cmdshell', 0
13 
14 GO
15 
16 RECONFIGURE
17 
18 GO

  导入和上面一样,但是要注意,

  执行完导出或导入工作后,出于对数据库安全性的考虑一定要禁用 'xp_cmdshell'

  我们弄完了要把SQLserver的值改回去,否则会出现各种异常。

如果有使用请标明来源:http://www.cnblogs.com/duwenlei/
原文地址:https://www.cnblogs.com/duwenlei/p/3513682.html