不用触发器
如果原表和两张新表在同一台机器上的话insert db2..b1 select ID,col1,col2 from db1..a
insert db2..b2 select ID,col3,col4 from db1..a

解决方案 »

  1.   

    select * into 新数据库..b1 from (select 字段1,字段2 ,...from 旧数据库..表名) a select * into 新数据库..b2 from (select 字段3,字段4 ,...from 旧数据库..表名) a
      

  2.   

    可以使用触发器例如:
    create trigger tr1 on a
    for insert 
    as
    insert into b1(col1,col2...) select acol1,acol2 ... from inserted
    insert into b2(col1,col2...) select acol3,acol4 ....from inserted
      

  3.   

    select inentity(int) id,...
    into database..b1
    from a
    where 1 = 2select inentity(int) id,...
    into database..b2
    from a
    where 1 = 2insert database..b1
    select ...
    from a
    order by 某一字段insert database..b2
    select ...
    from a
    order by 某一字段
      

  4.   

    如果已经存在表b1,b2
    insert b1 select ID,col1,col2..... from a
    insert b2 select ID,col3,col4..... from a如果不存在表b1,b2
    select ID,col1,col2..... into b1 from a 
    select ID,col3,col4..... into b2 from a
      

  5.   

    如果已经存在表b1,b2
    insert b1 select ID,col1,col2..... from a
    insert b2 select ID,col3,col4..... from a如果不存在表b1,b2
    select ID,col1,col2..... into b1 from a 
    select ID,col3,col4..... into b2 from a
    完全同意
      

  6.   

    CREATE TABLE b1
      (CustomerID   INTEGER PRIMARY KEY
                    CHECK (ID BETWEEN 1 AND 59999),
      ... -- Additional column definitions)CREATE TABLE b2
      (CustomerID   INTEGER PRIMARY KEY
                    CHECK (CustomerID BETWEEN 33000 AND 65999),
      ... -- Additional column definitions)
    insert into b1 (id...) select (id...) from a where a.id<59999
    insert into b2 (id...) select (id...) from a where a.id>59999在创建成员表后,定义一个分区视图。这样,如同原始表一样。这些视图使用分布式 SELECT 语句访问链接成员服务器上的数据,并若要为上一个示例创建分布式分区视图: 创建以下分区视图: 
    CREATE VIEW b AS
       SELECT * FROM b1
    UNION ALL
       SELECT * FROM b2
      

  7.   

    ID是只有b1,b2才有的字段的,a里面没有ID这个字段的
      

  8.   

    ID是只有b1,b2才有的字段的,a里面没有ID这个字段的
    ----
    你将你的b1,b2中的id设置为自增量,那么:truncate b1
    truncate b2
    go
    insert b1 select col1,col2..... from a
    insert b2 select col3,col4..... from a
      

  9.   

    不是,ID字段在b1是自增长的,在b2不是自增长的,而且b1和b2的ID要相对应才行
      

  10.   

    --楼主是要两个表保持同步?--即时同步两个表的实例:--测试环境:SQL2000,远程主机名:xz,用户名:sa,密码:无,数据库名:test--创建测试表,不能用标识列做主键,因为不能进行正常更新
    --在本机上创建测试表,远程主机上也要做同样的建表操作,只是不写触发器
    if exists (select * from dbo.sysobjects where id = object_id(N'[test]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
    drop table [test]create table test(id int not null constraint PK_test primary key
    ,name varchar(10))
    go--创建同步的触发器
    create trigger t_test on test
    for insert,update,delete
    as
    set  XACT_ABORT on
    --启动远程服务器的MSDTC服务
    exec master..xp_cmdshell 'isql /S"xz" /U"sa" /P"" /q"exec master..xp_cmdshell ''net start msdtc'',no_output"',no_output--启动本机的MSDTC服务
    exec master..xp_cmdshell 'net start msdtc',no_output--进行分布事务处理,如果表用标识列做主键,用下面的方法
    BEGIN DISTRIBUTED TRANSACTION
    delete from openrowset('sqloledb','xz';'sa';'',test.dbo.test)
    where id in(select id from deleted)
    insert into openrowset('sqloledb','xz';'sa';'',test.dbo.test)
    select * from inserted
    commit tran
    go--插入数据测试
    insert into test
    select 1,'aa'
    union all select 2,'bb'
    union all select 3,'c'
    union all select 4,'dd'
    union all select 5,'ab'
    union all select 6,'bc'
    union all select 7,'ddd'--删除数据测试
    delete from test where id in(1,4,6)--更新数据测试
    update test set name=name+'_123' where id in(3,5)--显示测试的结果
    select * from test a full join
    openrowset('sqloledb','xz';'sa';'',test.dbo.test) b on a.id=b.id
      

  11.   

    建议改一下表结构,a表中加自增字段。b1、b2用int型的ID,不自增。插入时就方便了。
      

  12.   

    --如果b1,b2表是空的.新建好的.b1的标识字段是这样设计的identity(1,1)--可以简单地这样处理
    insert into b1 select 字段1,字段2 from 原表
    insert into b2(字段3,字段4) select 字段3,字段4 from 原表declare @i int
    set @i=0
    update b2 set @i=@i+1,id=@i