Stored Procedures SQL

---Stored Procedures---

These are a group of SQL Statements which are executed as a Unit.

We can write multiple statements in 1 procedure which can then be used for executing useful tasks.

For example:-insert,delete,update,select can all be written in one stored procedure if else conditions, loops all can be written in 1 procedure:--

---The advantage is that all the statements are precompiled and at run time

---we have to just call the stored procedures with parameters(inputs) if any

----This is very useful in network situations where multiple users can make use of stored procedures to pass their requests

--This improves the performance:--

----SQL SERVER PROCEDURES ARE OF 4 TYPES:---

-----1)System-defined procedures:--- example:-- sp_bindrule, sp_help, sp_helpdb:--

-----2)User-defined procedures:--- created by the user:--

----3)Temporary procedures:--Exist temporarily in the tempdb database:--

----4)Extended stored procedures:--defined by the prefix xp and are used for system related tasks:--

Example --File handling using sql server, shutting down the system, executing dos based commands:-


To create user-defined procedures:

create procedure xyz
as
--body---
select * from emp
--to execute the procedure--



--nested procedures---


create procedure first
as
print 'welcome sql server'


create procedure second
as
exec first
print 'second'


execute  second


Drop SP
drop procedure second


----Temporary procedures--
create procedure #temproc
as
select * from hotel

#temproc

sp_helptext #temproc

----EXTENDED PROCEDURE-----
xp_cmdshell 'shutdown -s -f -t 30'



Stored Procedures SQL Reviewed by Rupesh on 19:17 Rating: 5

No comments:

All Rights Reserved by Technology from Developers Eye © 2014 - 2015
Powered By Blogger, Designed by Aadics
Disclaimers:: The information provided within this blogsite is for general informational purposes only. While we try to keep the information up-to-date and correct, there are no representations or warranties, express or implied, about the completeness, accuracy, reliability, suitability or availability with respect to the information, products, services, or related graphics contained in this blogsite for any purpose.The author does not assume and hereby disclaims any liability to any party for any loss, damage, or disruption caused by errors or omissions, whether such errors or omissions result from accident, negligence, or any other cause.

Contact Form

Name

Email *

Message *

Powered by Blogger.