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.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Kunal VaishyaPosted May 16, 2012, 5:38 AM
http://www.sql-server-performance.com/2003/stored-procedures-basics/
Satyapriya NayakPosted May 16, 2012, 5:12 AM
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