我有表A(id)。在插入新表時更新外鍵
我需要
- 創建表B(ID)
- 外鍵添加到表A中引用B.id
- 對A每一行,B中插入一行用B中新插入的行更新A.b_id
是否可以在B中添加引用A的臨時列?下面的工作,但我寧願不必做一個臨時專欄。
alter table B add column ref_id integer references(A.id);
insert into B (ref_id) select id from A;
update A set b_id = B.id from B where B.ref_id = A.id;
alter table B drop column ref_id;
你打我。太多的IDS。 – 2012-01-07 19:34:04
問題太混亂了嗎? – 2012-01-07 19:41:30
你的問題沒有意義。你真的想要達到什麼目標? – 2012-01-07 19:43:39