sql server遍历用户表导出所有表数据到文本

sql server遍历用户表相信大家都有一些了解,下面为您介绍的是sql server遍历用户表导出所有表数据到文本文件的方法,希望对您学习sql server遍历用户表方面能有所帮助。

 
 
 
  1. -- To allow advanced options to be changed.  
  2. EXEC sp_configure 'show advanced options', 1  
  3. GO  
  4. -- To update the currently configured value for advanced options.  
  5. RECONFIGURE  
  6. GO  
  7. -- To enable the feature.  
  8. EXEC sp_configure 'xp_cmdshell', 1  
  9. GO  
  10. -- To update the currently configured value for this feature.  
  11. RECONFIGURE  
  12. GO  
  13.  
  14. ---xp_cmdshell 'cd C:Program FilesMicrosoft SQL Server90ToolsBin'  
  15. xp_cmdshell 'dir *.exe'  
  16.  
  17.  
  18. SELECT NAME,NAME FROM SYS.OBJECTS  
  19. xp_cmdshell 'bcp northwind.dbo.orders out c:mytest -T -c'  
  20.  
  21. declare @sql nvarchar(max)  
  22. set @sql='' 
  23. select @sql=@sql+' xp_cmdshell '+'''bcp northwind.dbo.'+quotename(name)+' out c:'+name+'.dat -T -c '+''' ' from sys.objects    
  24. where type='u';  
  25. select @sql  
  26. exec (@sql) 

 

 

 

 

【编辑推荐】

SQL Server系统表的应用

Sql Server全文索引的迁移

SQL SERVER全文检索的实现

SQL Server删除用户失败的解决方法

sql server系统表说明

THE END