Reputation: 27
I am making some project where i have to insert multiple records in different different table. So, i have created a single procedure and write down my all insert statements in a single procedure. So, Is it good approach or not?
Below is example
Create proc dbo.InsCustomer
as
begin
insert a
select 1
insert b
select 1
insert c
select 1
insert d
select 1
End
Upvotes: 1
Views: 190
Reputation: 11222
Yes, this is a good idea. Any block of SQL code that belongs together can/should be executed on the database server in on go. This avoids multiple connections to the server from your application.
It also makes it easier to use a transaction around all the various statements.
Upvotes: 2