1.连接两个数据库,使用SQL的导入导出工具直接将一个表的数据导入另外一个库的这个表.2.在一个库中使用语句生成CSV或TXT文件,然后到另外一个库中导入.
/** 导入文本文件 
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' 

解决方案 »

  1.   


    BULK INSERT 库名..表名 
    FROM 'c:\test.txt' 
    WITH ( 
    FIELDTERMINATOR = ';', 
    ROWTERMINATOR = '\n' 
    ) 1、EXEC master..xp_cmdshell 'bcp dbname..tablename in c:\DT.txt 这个好像不支持多个表,如果要导出数个表,是否得导出对应个TXT文件?
    2、BULK INSERT 是什么意思,我查了下,并看了帮助还不是很明白怎么用。谢谢!
      

  2.   

    BULK INSERT
    以用户指定的格式复制一个数据文件至数据库表或视图中。语法
    BULK INSERT [ [ 'database_name'.][ 'owner' ].]{ 'table_name' FROM 'data_file' }
        [ WITH
            ( 
                [ BATCHSIZE [ = batch_size ] ]
                [ [ , ] CHECK_CONSTRAINTS ]
                [ [ , ] CODEPAGE [ = 'ACP' | 'OEM' | 'RAW' | 'code_page' ] ]
                [ [ , ] DATAFILETYPE [ =
                    { 'char' | 'native'| 'widechar' | 'widenative' } ] ]
                [ [ , ] FIELDTERMINATOR [ = 'field_terminator' ] ]
                [ [ , ] FIRSTROW [ = first_row ] ]
                [ [ , ] FIRE_TRIGGERS ]
                [ [ , ] FORMATFILE = 'format_file_path' ]
                [ [ , ] KEEPIDENTITY ]
                [ [ , ] KEEPNULLS ]
                [ [ , ] KILOBYTES_PER_BATCH [ = kilobytes_per_batch ] ]
                [ [ , ] LASTROW [ = last_row ] ]
                [ [ , ] MAXERRORS [ = max_errors ] ]
                [ [ , ] ORDER ( { column [ ASC | DESC ] } [ ,...n ] ) ]
                [ [ , ] ROWS_PER_BATCH [ = rows_per_batch ] ]
                [ [ , ] ROWTERMINATOR [ = 'row_terminator' ] ]
                [ , [ TABLOCK ] ] 
            ) 
        ] 
      

  3.   


    我想将A机子上的E、F、G表导出,再插入B机子上的E、F、G表中。其中E、F、G表的结构相同,是插入,不是导入,导入就把原来的数据都覆盖了。
      

  4.   

    insert into tb select * from 远程数据表select * into tb from opendatasource('SQLOLEDB','datasource='远程机器Ip';User ID=sa;Password= ')
      

  5.   

    用这个过程生成insert语句,记得把output的text长度设到足够长;如果有identity的字段要会设一个系统参数为off--exec spGenInsertSQL @tablename='tablename'CREATE proc [dbo].[spGenInsertSQL] (@tablename varchar(256))asbegin       set nocount on       declare @sqlstr varchar(8000)       declare @sqlstr1 varchar(8000)       declare @sqlstr2 varchar(8000)       select @sqlstr='select ''insert '+@tablename       select @sqlstr1=''       select @sqlstr2=' ('       select @sqlstr1= ' values ( ''+'       select @sqlstr1=@sqlstr1++col+'+'',''+' ,@sqlstr2=@sqlstr2+name +',' from (select case        when a.xtype =173 then 'case when '+a.name+' is null then ''NULL'' else '+'convert(varchar('+convert(varchar(4),a.length*2+2)+'),'+a.name +')'+' end'       when a.xtype =104 then 'case when '+a.name+' is null then ''NULL'' else '+'convert(varchar(1),'+a.name +')'+' end'       when a.xtype =175 then 'case when '+a.name+' is null then ''NULL'' else '+'''''''''+'+'replace('+a.name+','''''''','''''''''''')' + '+'''''''''+' end'       when a.xtype =61  then 'case when '+a.name+' is null then ''NULL'' else '+'''''''''+'+'convert(varchar(23),'+a.name +',121)'+ '+'''''''''+' end'       when a.xtype =106 then 'case when '+a.name+' is null then ''NULL'' else '+'convert(varchar('+convert(varchar(4),a.xprec+2)+'),'+a.name +')'+' end'       when a.xtype =62  then 'case when '+a.name+' is null then ''NULL'' else '+'convert(varchar(23),'+a.name +',2)'+' end'       when a.xtype =56  then 'case when '+a.name+' is null then ''NULL'' else '+'convert(varchar(11),'+a.name +')'+' end'       when a.xtype =60  then 'case when '+a.name+' is null then ''NULL'' else '+'convert(varchar(22),'+a.name +')'+' end'       when a.xtype =239 then 'case when '+a.name+' is null then ''NULL'' else '+'''''''''+'+'replace('+a.name+','''''''','''''''''''')' + '+'''''''''+' end'       when a.xtype =108 then 'case when '+a.name+' is null then ''NULL'' else '+'convert(varchar('+convert(varchar(4),a.xprec+2)+'),'+a.name +')'+' end'       when a.xtype =231 then 'case when '+a.name+' is null then ''NULL'' else '+'''''''''+'+'replace('+a.name+','''''''','''''''''''')' + '+'''''''''+' end'       when a.xtype =59  then 'case when '+a.name+' is null then ''NULL'' else '+'convert(varchar(23),'+a.name +',2)'+' end'       when a.xtype =58  then 'case when '+a.name+' is null then ''NULL'' else '+'''''''''+'+'convert(varchar(23),'+a.name +',121)'+ '+'''''''''+' end'       when a.xtype =52  then 'case when '+a.name+' is null then ''NULL'' else '+'convert(varchar(12),'+a.name +')'+' end'       when a.xtype =122 then 'case when '+a.name+' is null then ''NULL'' else '+'convert(varchar(22),'+a.name +')'+' end'       when a.xtype =48  then 'case when '+a.name+' is null then ''NULL'' else '+'convert(varchar(6),'+a.name +')'+' end'       when a.xtype =165 then 'case when '+a.name+' is null then ''NULL'' else '+'convert(varchar('+convert(varchar(4),a.length*2+2)+'),'+a.name +')'+' end'       when a.xtype =167 then 'case when '+a.name+' is null then ''NULL'' else '+'''''''''+'+'replace('+a.name+','''''''','''''''''''')' + '+'''''''''+' end'
           when a.xtype =36 then 'case when '+a.name+' is null then ''NULL'' else '+'''''''''+'+'replace('+a.name+','''''''','''''''''''')' + '+'''''''''+' end'       else '''NULL'''       end as col,a.colid,a.name       from syscolumns a where a.id = object_id(@tablename) and a.xtype <>189 and a.xtype <>34 and a.xtype <>35        )t order by colid              select @sqlstr=@sqlstr+left(@sqlstr2,len(@sqlstr2)-1)+') '+left(@sqlstr1,len(@sqlstr1)-3)+')'' from '+@tablename    print @sqlstr--       exec( @sqlstr)       set nocount offend
      

  6.   

    用vb寫個程序 ,將A機器的E、F、G表到出至一個Execl表的sheet中,再將此Excel表的數據插入B機器的E,F,G表
      

  7.   

    在一个机器上面建个IIS,用ASP代码就可以实现了。
      

  8.   

    用“WangDBtoCsv”,简洁,方便
      

  9.   

    如果是Oracle数据库的话,用WangDBtoCsv输出,自动形成CTL文件
    然后用SQLLDR加载即可,可自动甄别键值重复的记录。
    下载地址
    http://www.sharebank.com.cn/soft/SoftView_29038.htm