View
130
Download
7
Embed Size (px)
Citation preview
A stored procedure is a method to encapsulate
Tasks . A stored procedure is actually stored in
database data dictionary.
CREATE PROCEDURE <procedure name>
<Param> <datatype>
as
Begin
<Body of procedure>
End
//call <procedure name>(param value);
Create procedure getname(in int)
Begin
Select * from tbl_user where user_id=id;
End
Call getname(‘1002’);
Advantages
1. Maintainability
Scripts are in one location, updates and tracking of dependencies based on schema changes becomes
easier
2. Speed ……………………..Stored procedures are cached on the server. Execution
plans for the process are easily reviewable without having to run the application.
3.Reduced client sever trafficTo reduce network traffic between application server
and database sever
Disadvantage
Testing
Any data errors in handling Stored Procedures are not generated until runtime
Types of Stored Procedure
1. System Defined Stored Procedure
These stored procedure are already defined in Sql Server.
2. Extended Procedure..................................Extended procedures provide an interface to external programs for various
maintenance activities.
3.User Defined Stored Procedure...............
These procedures are created by user for own actions
4. CLR Stored Procedure...................................
CLR stored procedure are special type of procedure that are based on the CLR (Common Language Runtime) in .NET
framework.
cursors
SELECT INTO is fine for single row queries, but many applications require the querying of multiple rows of data
Use of cursor
For extracting multiple rows into variables from a table
Create table tbl_login(Vchr_name varchar(50),V chr_userid varchar(50));Create table tbl_user(Vchr_user_name varchar(50),Vchr_password varchar(50));Create procedure insert_value(@name varchar(50),@userid varchar(50),@username varchar(50),@password varchar(50))AsBeginInsert into tbl_login,tbl_user(vchr_name,vchr_user_id,vchr_username,vchr_password)values(@name,@userid,@username,@password)endexec insert_ value ‘ram’,’102’,’akhil’,’12345’;
Want to learn more about programming or Looking to become a good programmer?
Are you wasting time on searching so many contents online?
Do you want to learn things quickly?
Tired of spending huge amount of money to become a Software professional?
Do an online course @ baabtra.com
We put industry standards to practice. Our structured, activity based courses are so designedto make a quick, good software professional out of anybody who holds a passion for coding.
Follow us @ twitter.com/baabtra
Like us @ facebook.com/baabtra
Subscribe to us @ youtube.com/baabtra
Become a follower @ slideshare.net/BaabtraMentoringPartner
Connect to us @ in.linkedin.com/in/baabtra
Give a feedback @ massbaab.com/baabtra
Thanks in advancewww.baabtra.com | www.massbaab.com |www.baabte.com
Emarald Mall (Big Bazar Building)Mavoor Road, Kozhikode,Kerala, India.Ph: + 91 – 495 40 25 550
NC Complex, Near Bus StandMukkam, Kozhikode,Kerala, India.Ph: + 91 – 495 40 25 550
Cafit Square,Hilite Business Park,Near Pantheerankavu,Kozhikode
Start up VillageEranakulam,Kerala, India.
Email: [email protected]
Contact Us