Sql 插入父id为的子表记录
我有两个表父表和子表。我想同时插入父表和子表记录。但是子表具有父id。对不起,我的英语不好Sql 插入父id为的子表记录,sql,oracle,sql-server-2008,oracle10g,oracle11g,Sql,Oracle,Sql Server 2008,Oracle10g,Oracle11g,我有两个表父表和子表。我想同时插入父表和子表记录。但是子表具有父id。对不起,我的英语不好 Table 1 ======= fld_id name desc 1 sasi new_customer 2 arun old_customer Table 2 ======= fld_id fld_parent_id product 1 1 Dress 2 1 watch 3 1
Table 1
=======
fld_id name desc
1 sasi new_customer
2 arun old_customer
Table 2
=======
fld_id fld_parent_id product
1 1 Dress
2 1 watch
3 1 phone
4 2 Clock
5 2 pen
My input value like this
========================
1,sasi ,Dress|watch|phone
2,Arun ,Clock|pen
请帮助我完成此操作。您可能可以使用对象关系映射方案,但最终您必须先保存父对象,然后保存子对象。您将此项标记为sql server和oracle,你用的是什么数据库?蓝脚亲爱的杜德我用的是oracle和sqlserver。你能给我oracle或sqlserver的解决方案吗?先在父表中插入,然后在子表中插入。将两个插入放在一个SQL脚本中,然后运行该脚本。我不知道还有什么方法可以实现你想要的。
begin
insert into parent_table; --insert statement for parent table
insert into child table ; --insert statement for child table
commit;
end;