In this blog, you will learn how to insert multiple values in the multiple tables, using stored procedure. You have inserted multiple values in the multiple tables one by one in SQL Server. Today, you will learn how to insert multiple values in multiple tables, using stored procedure. I have shared below queries and screenshots. You can follow them and you will easily understand how to insert multiple values in the multiple tables as well.
First, you make table in SQL Server. I have made a table and named it as Empl. You can see SQL query, given below-
- create table Empl(E_ID int primary key identity(1,1), Name varchar(50), Designation varchar(50))
- create table Location(L_ID int primary key identity(1,1), Location varchar(50), E_ID int foreign key references Empl(E_ID))
- create table Contact_Emp (C_ID int primary key identity(1,1), Contact_Number varchar(50), Lo_ID int foreign key references Location(L_ID))
- create proc InsertMultiplevalue
- (
- @Name varchar(50),
- @Designation varchar(50),
- @Location varchar(50),
- @Contact varchar(50)
- )
- as
- begin
- insert into Empl values(@Name, @Designation)
- declare @Employee_ID int = @@identity
- insert into Location values(@Location,@Employee_ID)
- declare @Cot_ID int = @@identity
- insert into Contact_Emp values(@Contact,@Cot_ID)
- end
- exec InsertMultiplevalue 'Asif Ali','Programmer','Hyderabad','[email protected]'

ch chandrakalaPosted Nov 24, 2019, 5:38 AM
Without identity(means primary key and fk relation) how can i insert..
Mujahid SacPosted Oct 24, 2017, 4:50 AM
Salam Ali, I tried inserting using the same variables for each of my tables, but it doesn't work. What is wrong? Is there a way I can enter the same variables/values for columns in multiple tables?
SubashPosted Oct 5, 2016, 5:44 AM
Good Share