如有库db1,db2,都有表t,现在将db1中的t中的数据导入到db2中
insert into db2..t(col1,col2...)
select col1,col2... from db1..t如果存在着自动编号id,则:
set identity_insert id on
insert into db2..t(id,col2...)
select id,col2... from db1..t
set identity_insert id off

解决方案 »

  1.   

    insert into 库名1.所有着1.表名1(col1,col2...)
    select col1,col2... from 库名2.所有着2.表名2
      

  2.   

    insert into databasename1.dbo.tablename select * from tablename
      

  3.   

    应该是:
    如果存在着自动编号id,则:
    set identity_insert db2..t on
    insert into db2..t(id,col2...)
    select id,col2... from db1..t
    set identity_insert db2..t off
      

  4.   

    老兄!我试了一下!你可以直接用DTS!因为DTS也是执行INSERT操作!
    下面是DTS系统执行时的脚本:
    insert bulk [aspnet].[dbo].[TABLE1]("id" char(10) COLLATE Chinese_PRC_CI_AS,"name" char(10) COLLATE Chinese_PRC_CI_AS,"age" char(10) COLLATE Chinese_PRC_CI_AS)with(check_constraints)
      

  5.   

    insert into 另一个库..表名 select * from 一个库..表名
      

  6.   

    insert into 目的数据库名.dbo.目的表 select * from 源数据库名.dbo.源表
      

  7.   

    --加上列名,这样即使原表中有自动编号也没关系!
    insert into 库名1.所有着1.表名1(col1,col2...)
    select col1,col2... from 库名2.所有着2.表名2
      

  8.   

    本表后面的还用写清楚吗?
    如上面的   select * from 源数据库名(.dbo.源表)
    ()内的可以不写吗?
      

  9.   

    yijiumao(一九猫):
        不是省略表名,是省略库名。
        select * from 表名