Here is this post we will discuss how to write a single stored procedure that will insert, update and delete in the table in Sql server 2008. Also you can check out my previous posts on:
- stored procedure to update record in sql server 2008
- Call stored procedure in Asp.Net using C#.Net
- What are the various behaviors managed by the Service Runtime layer in WCF ?
Below are steps for performing common stored procedure in sql server.
Right click on stored procedure, then add new stored procedure. Here the stored procedure will take 5 parameters. Based on the @action parameter we will inset, update or delete the record.
Create procedure sp_InserUpdateDelete
@id integer;
@name varchar(20);
@add varchar(20);
@img varchar(20);
@action varchar(20)
As
if(@action='I')
begin
Insert into emp_master(emp_name,emp_address,emp_image) value (@name,@add,@img)
end
if(@action='U')
begin
Update emp_master set emp_name=@name,emp_address=@add,emp_image=@img where emp_id=@id
end
if(@action='D')
begin
Delete from emp_master where emp_id=@id
end
Return
Then save the stored procedure by pressing CTRL+S where emp_master is the table name , sp_InserUpdateDelete is the procedure name.
- stored procedure to update record in sql server 2008
- Call stored procedure in Asp.Net using C#.Net
- What are the various behaviors managed by the Service Runtime layer in WCF ?
Below are steps for performing common stored procedure in sql server.
Right click on stored procedure, then add new stored procedure. Here the stored procedure will take 5 parameters. Based on the @action parameter we will inset, update or delete the record.
Create procedure sp_InserUpdateDelete
@id integer;
@name varchar(20);
@add varchar(20);
@img varchar(20);
@action varchar(20)
As
if(@action='I')
begin
Insert into emp_master(emp_name,emp_address,emp_image) value (@name,@add,@img)
end
if(@action='U')
begin
Update emp_master set emp_name=@name,emp_address=@add,emp_image=@img where emp_id=@id
end
if(@action='D')
begin
Delete from emp_master where emp_id=@id
end
Return
Then save the stored procedure by pressing CTRL+S where emp_master is the table name , sp_InserUpdateDelete is the procedure name.