在主要细节中插入记录 [英] inserting record in master detail
问题描述
我有两个桌子
1. sell_master,字段为in_sell_id(identity),mn_sell_amount
2. sell_detail,字段为in_sell_id(非身份),vc_item_name
从aspx页面,我将记录插入上述表格中,当我单击提交"按钮时,应在sell_master中插入一条记录,并在sell_detail表中插入与最近生成的ID相对应的记录.
例如:
sell_master
--------------
in_sell_id mn_sell_amount
1500
2 800
sell_detail
--------------------
in_sell_id vc_item_name
1汁
1种糖果
2个窗格
2只鸡
我该如何与上述相同?
I have two table
1. sell_master, fields are in_sell_id(identity),mn_sell_amount
2. sell_detail, fields are in_sell_id(not identity),vc_item_name
from aspx page i am inserting record in above mentioned table, When i click on submit button one record should inserted in sell_master and record corrusponding recent generated id should inserted in sell_detail table.
For ex :
sell_master
--------------
in_sell_id mn_sell_amount
1 500
2 800
sell_detail
--------------------
in_sell_id vc_item_name
1 juice
1 sweets
2 paneer
2 chicken
How can i do same as above ?
推荐答案
您可以使用 ^ ]以获取最近生成的ID.这是一个示例方法
You can use SCOPE_IDENTITY[^] to get the recent generated Id. Here is a sample approach
INSERT INTO sell_master ( mn_sell_amount) VALUES (500)
DECLARE @in_sell_id INT
SET @in_sell_id = SCOPE_IDENTITY()
INSERT INTO sell_detail(in_sell_id, vc_item_name) VALUES (@in_sell_id,'juice')
INSERT INTO sell_detail(in_sell_id, vc_item_name) VALUES (@in_sell_id,'sweets')
这篇关于在主要细节中插入记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!