如何在两个表之间有父子关系的情况下将记录插入到两个表中 [英] How to insert a record into 2 tables whe there is a parent, child relation between them

查看:102
本文介绍了如何在两个表之间有父子关系的情况下将记录插入到两个表中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有2个表,并且我已为父表获取了主键,为子表获取了外键.基于主键表,我正在从子表中检索数据.
在这种情况下,我想添加一条新记录,该记录未存储在两个表中.你能告诉我怎么做吗?帮帮我.

I have 2 tables and I have taken a primary key for parent table and a foreign key for child table. Based on primary key table I am retrieving data from the child table.
In this case I want to add a new record, which is not stored in both tables. Can you tell me how it is done? Help me.

推荐答案

您需要先填充子表,获取插入行的唯一键,然后在插入父表时将其用作外键桌子.

就像依赖的对象将在稍后填充.
You would need to first populate the child table, get the unique key for the row inserted and then use that as foreign key while inserting in the parent table.

It''s like the one which is dependant will be filled later.


这篇关于如何在两个表之间有父子关系的情况下将记录插入到两个表中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆