日期:2014-05-18  浏览次数:20473 次

怎样把TXT文件的数据导入SQL2005数据库中
怎样把TXT文件的数据导入SQL2005数据库中,求代码???

------解决方案--------------------
SQL code
 
/** 导入文本文件 */
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'

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'


BULK INSERT 库名..表名
FROM 'c:\test.txt'
WITH (
FIELDTERMINATOR = ';',
ROWTERMINATOR = '\n'
)


------解决方案--------------------
SQL code
/** 导入文本文件 
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' 
或 
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' 


BULK INSERT 库名..表名 
FROM 'c:\test.txt' 
WITH ( 
FIELDTERMINATOR = ';', 
ROWTERMINATOR = '\n' 
)