首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > SQL Server >

sqlserver备份一张表解决方案

2013-01-04 
sqlserver备份一张表如何将一张表user备份成txt文件,保存到路径为c:\下求sql语句我用的是sqlserver2005[解

sqlserver备份一张表
如何将一张表user备份成txt文件,保存到路径为c:\下

求sql语句

我用的是sqlserver2005
[解决办法]

EXEC sp_configure 'show advanced options', 1 
RECONFIGURE WITH OVERRIDE 
EXEC sp_configure 'xp_cmdshell', 1 
RECONFIGURE WITH OVERRIDE  
EXEC sp_configure 'show advanced options', 0

exec master..xp_cmdshell 'bcp dbname..tablename out c:\d.txt -c -S. -Usa -P'

[解决办法]

/** 导入文本文件 */
EXEC master..xp_cmdshell 'bcp dbname..tablename in c:/DT.txt -c -Sservername -Usa -Ppassword' 
/** 导出文本文件 */
EXEC master..xp_cmdshell 'bcp dbname..tablename out c:/DT.txt -c -Sservername -Usa -Ppassword' 
--or
EXEC master..xp_cmdshell 'bcp "Select * from dbname..tablename" queryout c:/DT.txt -c -Sservername -Usa -Ppassword' 
/**导出到TXT文本,用逗号分开*/ 
exec master..xp_cmdshell 'bcp "库名..表名" out "d:/tt.txt" -c -t ,-U sa -P password' 

热点排行