Introduction: Today I am going to explain how we can Get, Insert, Update and Delete the records using one store procedure in sql server
Now I create a store procedure to perform all action:
Create procedure Emp_Tb_IUDS
@id int =null,
set nocount on;
if @command ='Insert' --To insert the records
insert into dbo.tb_Emp (Emp_Name,Emp_Address,Emp_Salary,Emp_PhoneNo) values(@name,@address,@salary,@phoneN)
else if @command='Update' --To Update the records
Update dbo.tb_Emp set Emp_Name=@name,Emp_Address=@address,Emp_Salary=@salary,Emp_PhoneNo=@phoneN where
Else if @command = 'Delete' --To Delete the records
Delete from dbo.tb_Emp where Id = @id
Else if @command = 'Select' --To Select the records
Select * from dbo.tb_Emp
To check the store procedure is working properly or not, execute it.
To insert the records:
Exec Emp_Tb_IUD @command='Insert',@name='Ramesh',@address='Himachal pradesh',@salary=10000,@phoneN=78456123
To update the records:
Exec Emp_Tb_IUD @command='Update',@id='1',@name='Tarun',@address='Delhi',@salary=24000,@phoneN=741258635
To delete the records:
Exec Emp_Tb_IUD @command='Delete',@id='2'
To select the records:
Exec Emp_Tb_IUD @command='Select'
Is this article helpful for you?
If yes post your comment to appreciate my work and fell free to contact me. You can like me on Facebook, Google+, Linkedin and Twitter via hit on Follow us Button and also can get update follow by Email.
What do you think about this article?
If you found this article useful, please share and follow on Facebook, Twitter, Google Plus and other social media websites. To get free updates subscribe to newsletter. Please put your thoughts and feedback in comments section.