我要将unix格式的文本文件直接导入SQLserver要怎么写?
我手工转化为dos格式就可以导入,不转化就导不进去,有没有什么参数可以设置直接导入unix格式的txt文件?
在线等,急!

解决方案 »

  1.   

    --前序,开启xp_cmdshell 
    --关于xp_cmdshell的一些知识 请看 http://blog.csdn.net/feixianxxx/archive/2009/08/14/4445603.aspx
    EXEC sp_configure 'show advanced options', 1;RECONFIGURE;
    EXEC sp_configure 'xp_cmdshell', 1;RECONFIGURE;
    --环境
    create table test
    (
        id int,
        value varchar(100)
    )
    go
    insert test values(1,'s1')
    insert test values(2,'s2')
    insert test values(3,'s3')
    insert test values(4,'s4')
    go
    --1将表的数据导出到TEXT.txt文件中
    exec master..xp_cmdshell 'bcp tempdb.dbo.test out e:\test.txt -c  -Usa -P123456'
    --如果是WINDOWS身份 直接 xec master..xp_cmdshell 'bcp tempdb.dbo.test out e:\test.txt -T -c'--2将TEXT.txt文件中的数据复制到test1表
    select * into test1 from test where 1=2
    exec master..xp_cmdshell 'bcp tempdb.dbo.test1 in e:\test.txt -c  -Usa -P123456'
    select * from test1--3将TEST表的ID字段复制到TEXT.txt中
    exec master..xp_cmdshell 'bcp "SELECT id FROM tempdb.dbo.test" queryout e:\test.dat -T -c'--4将test表中的第一行移动到text.txt中
    exec master..xp_cmdshell 'bcp "SELECT top 1 * from tempdb.dbo.test "  queryout e:\test.txt -c  -Usa -P123456'--关闭xp_cmdshell
    EXEC sp_configure 'show advanced options', 1;RECONFIGURE;
    EXEC sp_configure 'xp_cmdshell', 0;RECONFIGURE;
      

  2.   

    http://topic.csdn.net/u/20100330/11/767db3c8-3ae0-4c55-af61-f342a78c29ba.html?43333
      

  3.   

    你的第2个exec master..xp_cmdshell 'bcp tempdb.dbo.test1 in e:\test.txt -c  -Usa -P123456'
    test.txt应该是dos格式的吧,我想知道的是如果test.txt是unix格式如何导入,-c这个参数就不行了,改成-6可以导入一部分但是有乱码
      

  4.   

    bcp命令执行后的日志文件在哪里?
      

  5.   

    记得06年时,我们也是讲unix编码方式转成dos编码才行