How to create a store procedure with example
how to create a store procedure with example and why we use stored procedure.
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Satyapriya NayakRank #47 · 31.5K reputationPosted May 16, 2012, 1:12 AM EDT
Its nothing but a set of T-SQL statements combined to perform a single task of several tasks. Its basically like a Macro so when you invoke the Stored Procedure, you actually
run a set of statements. Stored Procedure are the precompiled set of sql command.
Stored procedures means containing a precompiled block of code. if we call stored procedures they need not compiled, only execution takes place. With this advantage, work on database is less.
Example
Create table student (sid varchar(50),sname varchar(50),smarks int,saddress varchar (50),year varchar(50))
For display records
CREATE PROCEDURE display
AS
select * from student
For insert records
CREATE PROCEDURE insert
(@sid varchar(50),@sname varchar(50),@smarks int,@saddress varchar (50),@year varchar(50))
AS
insert student(sid,sname,smarks,saddress,year) values (@sid,@sname,@smarks,@saddress,@year)
For update records
CREATE PROCEDURE update
(@sid varchar(50),@sname varchar(50),@smarks int,@saddress varchar (50),@year varchar(50))
AS
update student set sname=@sname,smarks=@smarks,saddress=@saddress,year=@year where sid=@sid
For delete records
CREATE PROCEDURE delete
(@sid varchar(50))
AS
delete from student where sid=@sid
Please refer the below link
http://msdn.microsoft.com/en-us/library/ms190669%28v=sql.105%29.aspx
Thanks
Kunal VaishyaRank #990 · 2K reputationPosted May 16, 2012, 1:38 AM EDT
http://www.sql-server-performance.com/2003/stored-procedures-basics/