How can data insert/update/delete in a table using a stored procedure?

986    Asked by HarryButler in SQL Server , Asked on Jan 18, 2020
Answered by Rachit Gupta

We can insert/update/delete data in the table by passing the values in parameters and inserting /updating/ deleting the data into the table. After operations the best thing is to get the output so that it is confirmed that the requirement is fulfilled or not.

In the below procedure insert is tested, however update/delete statements can be changed as per requirement

-- Create Stored Procedure

create PROCEDURE usp_TestInsertTable

@p_First VARCHAR(50),

@p_Second VARCHAR(50),

@p_Result VARCHAR(50) out

AS

begin

insert into input_values –- Insert data in table from input parameter

select @p_First,@p_Second

set @p_Result= @@ROWCOUNT; --get the count of records at the end of the result

end

-- execute the procedure

 go

declare @p_Result VARCHAR(50)

 exec usp_TestInsertTable 'Data1', 'data2' , @p_Result out

select @p_Result output_value -–check data from the variable

select * from input_values -–check data in the table



Your Answer

Interviews

Parent Categories