0

からの値を別のテーブル B に挿入したいですtable A。問題は、テーブル B に外部キーである別のいくつかの列が含まれていることです。

  • Table A:ID, Fatherid, MotherID, ParentOccupation
  • Table B:ID, 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

tableBの外部キー以外の対応する列を挿入するだけです。tableB のすべての fk 列で null が指定されていない場合は、対応する null 値を挿入します

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