This snippet is a query which does select Insert operation into a table. We here would see that creating a Stored procedure which actually selects the data from a table and may be insert into the same table or other tables with identical columns. here I would show you how to insert into the same table.
This is really handy when there is a huge amount of records to be selected and inserted and using foreach in Entity Framework would hamper the performance heavily.
This is really handy when there is a huge amount of records to be selected and inserted and using foreach in Entity Framework would hamper the performance heavily.
ALTER PROCEDURE [dbo].[spAddRecordsForNewX]
-- Add the parameters for the stored procedure here
@fkID INT,
@conditionID INT,
AS
BEGIN
--================== SELECT INSERT QUERY FOR THE RESPECTIVE TABLE RECORDS=================--
BEGIN TRANSACTION
INSERT INTO
dbo.[TABLE#]
SELECT
@fkID,
pRel.Column1,
pRel.Column2,
pRel.Column3,
pRel.Column4,
pRel.Column5,
FROM
dbo.[TABLE#] as pRel
WHERE
PRIMARYKEY = @conditionID --This would be a primary key condition to retrive and Insert the codes
IF @Rollback = 1
ROLLBACK TRANSACTION
ELSE
COMMIT
//The transanction is trackerd and rolled back if any issueI hope this helps.
Please use it and improve performance.
Thanks
