0

我想将值table A插入另一个表 B。问题是表 B 包含另外几列是外键。

  • Table AID, Fatherid, MotherID, ParentOccupation
  • Table BID, Fatherid, MotherID, ParentOccupation, TrID

inTable B Trid是外键。但我希望将所有其他列从表 A 复制到 B。

是否可以将表A的行复制到表B?

请帮忙。

4

2 回答 2

0
insert into table_b
select
    col1,
    col2,
    col3, 
    ...
    (select some_key_value
     from some_primary_table
     where <some condition based on table_a's values>),
    (select some_key_value2
     from some_primary_table2
     where <some condition based on table_a's values>),
    ...
from table_a
于 2012-10-31T06:19:57.880 回答
0

您可以只插入相应的列,而不是表B中的外键。如果tableB的所有fk列都不为null,则对应插入null值

insert into tableB(col1,colu2..) 
values (select col1,col2.. from tableA)
于 2012-10-31T06:20:07.597 回答