sqlserver2000三个表:a,b,c 
a fileid (自增字段) 
b serid(自增字段) 
c fileid serid 
我想在数据库自动插入b.serid 和a.fileid 的时候将这两个字段提取出来同时插入c fileid serid有没有什么好方法?

解决方案 »

  1.   

    declare @a_id int,@b_id int;insert a ....set @a_id = @@identity;insert b ...set @b_id =@@identityinsert c values(@a_id,@b_id);
      

  2.   

    牵扯到楼上josy说的一个问题:
    如果 b serid已经存在了,a fileid又想再自增一个,但这个时候b serid没有自增,他们之间的联系是通过都有的cdate(记录最新操作时间的也就是getdate())字段,那么如何通过cdate字段来更新c表?
      

  3.   

    CREATE PROCEDURE  test  
    @filetest intas
      
       declare @file1 int,@sei1 int
       select a.fileid , b.msgserid  from filecont a,ifshowmsg b where datediff(second ,a.cdate,b.cdate)=0 and msgserid=@filetest
       set @file1= a.fileid
    set @file1= a.fileid说这一句有问题!
    filecont表里有 fileid     cdate
                   100   2009-6-2 18:02:30
    ifshowmsg表里有 msgserid      cdate
                     200     2009-6-2 18:02:30
    现在是把这两个表里 cdate时间相同的fileid msgserid 插入到一个c表中,该怎么写这个存储过程啊?时间相同到秒相同就行了!
      

  4.   

    批量插入时间就一样的
    insert into table 
    select a.fileid , b.msgserid  from filecont a,ifshowmsg b where datediff(second ,a.cdate,b.cdate)=0 and msgserid=@filetest
      

  5.   

    是不是c表里必须要有fileid和msgserid这两个字段?
      

  6.   

    就直接insert into table???
      

  7.   

    直接insert into table ????