做项目要输入一些数据进行测试,假设有a表(id)b表(bid,aid)其中id,bid都为主键,aid为外键,现在a表有数据200条,想要在b表中加入数据怎么加
还有写存储过程如何先删除表中数据(先判断有没有数据),再往里面插入数据
不好意思,菜鸟一个,分也不多

解决方案 »

  1.   

    a表和b表有联系吗?感觉用不上a表哦
      

  2.   

    if not exists(select 1 from tbb where aid in (select id from tba where 条件))
    insert tbb
    values(aid)
    select id from tba
    where 条件
      

  3.   


    insert into b select * from a not exists (select 1 from b where a.字段=b.字段)
      

  4.   

    你插入b表的数据 是不是A表里的BID么?
      

  5.   

    先把问题描述清楚吧,想往B表中插入什么样的数据?
    id    aid
    1     1
    2     1
    3     2
    4     2
    这样的?
      

  6.   

    1、说明:复制表(只复制结构,源表名:a 新表名:b) (Access可用) 
    法一:select * into b from a where 1 <>1 
    法二:select top 0 * into b from a 2、说明:拷贝表(拷贝数据,源表名:a 目标表名:b) (Access可用) 
    insert into b(a, b, c) select d,e,f from a; 
      

  7.   

    ytmf007,把你的问题说清楚吧。
      

  8.   

    既是a表中id都有了,现在想往b表中插入数据,其中bid为b表主键,然后aid为a表外键
    a表
    id 550
    id 551
    .....
    b表
    bid aid
    331 550
    332 551
    .....
      

  9.   

    b表中还有其他数据,如name字段
      

  10.   

    既往b表中加入a表中id还有其他数据