本文介绍了关系数据库问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
请为我解决问题:
我有一个名为tblAddress的表,其中包含以下字段:
地址ID,
地址1,
地址2,
状态,
国家.
该表与另一个名为tblEmployee的表相关,具有以下字段:
EmpID,
地址ID,
FName,
LName
我的问题是如何将数据立即插入两个表中,因为必须将addressid插入两个表中,以便我轻松检索.
Kindly solve my problem for me:
I have a table named tblAddress that contain these fields:
AddressID,
Address1,
Address2,
State,
Country.
This table is related to another one named tblEmployee with the following fields:
EmpID,
AddressID,
FName,
LName
My problem is how to insert data into the two tables at once since the addressid must be inserted into the two tables, so that it will easy for me to retrieve.
推荐答案
INSERT tblAddress(Address1, Address2, State, Country)
VALUES(@Add1, @Add2, @State, @Country)
DECLARE @ID INT = SCOPE_IDENTITY()
INSERT tblAddress(AddressID, FName, LName)
VALUES(@ID, @FName, @LName)
这篇关于关系数据库问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!