SlideShare uma empresa Scribd logo
1 de 27
PRESENTATION  STORE PROCEDURE Presented By –  Prabhu P
Overview ,[object Object]
Difference between SP and Function
How to create a store procedure
How to call.
Initial Processing - ReviewResolution Compilation/Optimization Execution/Recompilation ,[object Object],When do you want to Recompile? Options for Recompilation?  What to Recompile?
What is store procedure? A stored procedure is a set of SQL commands that has been compiled and stored on the  database  server. 	Once the stored procedure has been "stored", client applications can execute the stored procedure over and over again without sending it to the database server again and without compiling it  again. 	Stored procedures improve performance by reducing network  traffic and CPU  load.
Comparison with dynamic SQL ,[object Object]
Avoidance  of  network  traffic
Encapsulation  of  business  logic
Delegation  of  access-rights
Some protection from SQL injection attacks,[object Object],[object Object]
Syntax Of Store ProcedureWith Parameter -- ============================================= -- Author:         <Author,,Name> -- Create date: <Create Date,,> -- Description:<Description,,> -- ============================================= Create   Proc   SP_Name ( 	Param1 	DataType, 	param2	DataType, 	Param3 	DataType, 	. 	. 	. ParamnDataType ) As 	Begin 		Body Of Store Procedure 	End
Implementation: -- ============================================= 	-- Author:	<Author:  XYZ> 	-- Create date: 	<Create Date:23/06/2010> 	-- Description:	< Used  to retrieve all information  of  an employee 		Information of  from the  Table ‘EmployeeInfo’  according to 		supplied Employee ID> -- ============================================= Create Proc SP_FetchSpecificEmployeeInfo ( EmpIdverchar(50) ) As 	Begin 		Select * from EmployeeInfo where EmployeeID= EmpId 	End
Syntax Of Store ProcedureWith out Parameter -- ============================================= -- Author:         <Author,,Name> -- Create date: <Create Date,,> -- Description:<Description,,> -- ============================================= Create   Proc   SP_Name 	As 	Begin 		Body Of Store Procedure 	End
Implemetaion -- ============================================= 	-- Author:	<Author:  XYZ> 	-- Create date: 	<Create Date:23/06/2010> 	-- Description:	< Used  to retrieve all information of  the table 	‘EmployeeInfo’  without any Condition> -- ============================================= Create Proc SP_FetchAllEmployeeInfo     As 	Begin 		Select  * from EmployeeInfo 	End
Using SP How  To Insert Information -- ============================================= 	-- Author:		< XYZ> 	-- Create date: 	<23/06/2010> 	-- Description:	< Used  To Insert Employee Information > -- ============================================= CREATE proc  SP_InsertEmployeeInfo ( 	@ID				varchar(20) , 	@Name				varchar (50) , 	@Pin				varchar(20),	 	@Email				varchar(50),	 	@MobileNovarchar(20), 	@PhoneNovarchar(20), 	@MailingAddrvarchar(500) , 	@ParmanentAddrVarchar(500) , 	@Sex				varchar(10) , 	@JoingDatesmalldatetime , 	@Post				varchar(50) 	 )
AS 	Begin 		if exists(Select ID From  EmployeeInfo Where ID = @ID) 		Begin 			return 0 		End 		else  			Begin 			Insert into  EmployeeInfo 			( 		ID				 		,Name			 		,Pin			 		,Email			 		,MobileNo 		,PhoneNo 		,MailingAddr 		,ParmanentAddr 		,Sex			 		,JoingDate 		,Post		 			)
values 	( 		@ID				 		,@Name			 		,@Pin			 		,@Email			 		,@MobileNo 		,@PhoneNo 		,@MailingAddr 		,@ParmanentAddr 		,@Sex			 		,@JoingDate 		,@Post 	) 	End 		Begin 			return 1 		End  	End
Using SP How To  Update  Information -- ============================================= 	-- Author:		< XYZ> 	-- Create date: 	<3/06/2010> 	-- Description:	<Used To Update Record Of  EmployeeInfo Table > -- ============================================= CREATE proc  SP_UpdateEmployeeInfo ( 	@ID			varchar(20) , 	@Name			varchar (50) , 	@Pin			varchar(20),	 	@Email			varchar(50),	 	@MobileNovarchar(20), 	@PhoneNovarchar(20), 	@MailingAddrvarchar(500) , 	@ParmanentAddrVarchar(500) , 	@Sex			varchar(10) , 	@JoingDatesmalldatetime , 	@Post			varchar(50)  )
AS 	Begin     		if not exists(select id from  EmployeeInfo where  ID = @ID) 			Begin     				 return 0 			End	 	   	 else		 			Begin				 				Update  EmployeeInfo 				set				 				Name		=@Name			 		,Pin		=@Pin	 		,Email		=@Email	 		,MobileNo		=@MobileNo 		,PhoneNo		=@PhoneNo 		,MailingAddr 	= @MailingAddr 		,ParmanentAddr  	=@ParmanentAddr 		,Sex		=@Sex 		,JoingDate		=@JoingDate 		,Post		=@Post 				where  ID		=@ID	 				return 1			 			End	 	End
Using SP How TO  Delete Record  -- ============================================= 	-- Author:		< XYZ> 	-- Create date: 	<3/06/2010> 	-- Description:	<Used To Delete Record From EmployeeInfo Table > -- ============================================= CREATE PROC  SP_DeleteEmployeeInfo ( 	@id varchar(20) ) AS 	Begin    		 if not exists(select id from EmployeeInfo where  id = @id) 			Begin     				 return 0 			End 	  	  else
	Begin 	if  exists(select * from EmployeeInfo where id = @id and DeleteStatus = 0) 			Begin 				return 1 			End 	else 			Begin 				delete from  EmployeeInfo where id =  @id 				return 2 			End 	End	 End
How To Execute SP ,[object Object]
Syntax	EXEC   SP_NAME   ,[object Object],	EXEC    SP_FetchAllEmployeeInfo ,[object Object]
Syntax
EXEC SP_NAME  PARAMETER_lIST

Mais conteúdo relacionado

Mais procurados

Procedures/functions of rdbms
Procedures/functions of rdbmsProcedures/functions of rdbms
Procedures/functions of rdbmsjain.pralabh
 
Procedures and triggers in SQL
Procedures and triggers in SQLProcedures and triggers in SQL
Procedures and triggers in SQLVikash Sharma
 
5. stored procedure and functions
5. stored procedure and functions5. stored procedure and functions
5. stored procedure and functionsAmrit Kaur
 
Intro to tsql unit 15
Intro to tsql   unit 15Intro to tsql   unit 15
Intro to tsql unit 15Syed Asrarali
 
Intro to tsql unit 12
Intro to tsql   unit 12Intro to tsql   unit 12
Intro to tsql unit 12Syed Asrarali
 
Intro to tsql unit 6
Intro to tsql   unit 6Intro to tsql   unit 6
Intro to tsql unit 6Syed Asrarali
 
MySQL Stored Procedures: Building High Performance Web Applications
MySQL Stored Procedures: Building High Performance Web ApplicationsMySQL Stored Procedures: Building High Performance Web Applications
MySQL Stored Procedures: Building High Performance Web ApplicationsOSSCube
 
Sql server ___________session_18(stored procedures)
Sql server  ___________session_18(stored procedures)Sql server  ___________session_18(stored procedures)
Sql server ___________session_18(stored procedures)Ehtisham Ali
 
An Introduction To PostgreSQL Triggers
An Introduction To PostgreSQL TriggersAn Introduction To PostgreSQL Triggers
An Introduction To PostgreSQL TriggersJim Mlodgenski
 
Tony Jambu (obscure) tools of the trade for tuning oracle sq ls
Tony Jambu   (obscure) tools of the trade for tuning oracle sq lsTony Jambu   (obscure) tools of the trade for tuning oracle sq ls
Tony Jambu (obscure) tools of the trade for tuning oracle sq lsInSync Conference
 
Tony jambu (obscure) tools of the trade for tuning oracle sq ls
Tony jambu   (obscure) tools of the trade for tuning oracle sq lsTony jambu   (obscure) tools of the trade for tuning oracle sq ls
Tony jambu (obscure) tools of the trade for tuning oracle sq lsInSync Conference
 

Mais procurados (20)

Stored procedure
Stored procedureStored procedure
Stored procedure
 
Triggers and Stored Procedures
Triggers and Stored ProceduresTriggers and Stored Procedures
Triggers and Stored Procedures
 
Procedures/functions of rdbms
Procedures/functions of rdbmsProcedures/functions of rdbms
Procedures/functions of rdbms
 
Stored procedure
Stored procedureStored procedure
Stored procedure
 
Stored procedure in sql server
Stored procedure in sql serverStored procedure in sql server
Stored procedure in sql server
 
Procedures and triggers in SQL
Procedures and triggers in SQLProcedures and triggers in SQL
Procedures and triggers in SQL
 
5. stored procedure and functions
5. stored procedure and functions5. stored procedure and functions
5. stored procedure and functions
 
Sql triggers
Sql triggersSql triggers
Sql triggers
 
Intro to tsql unit 15
Intro to tsql   unit 15Intro to tsql   unit 15
Intro to tsql unit 15
 
Intro to tsql
Intro to tsqlIntro to tsql
Intro to tsql
 
Database Testing
Database TestingDatabase Testing
Database Testing
 
Intro to tsql unit 12
Intro to tsql   unit 12Intro to tsql   unit 12
Intro to tsql unit 12
 
Chapter 4 functions, views, indexing
Chapter 4  functions, views, indexingChapter 4  functions, views, indexing
Chapter 4 functions, views, indexing
 
Intro to tsql unit 6
Intro to tsql   unit 6Intro to tsql   unit 6
Intro to tsql unit 6
 
PL/SQL TRIGGERS
PL/SQL TRIGGERSPL/SQL TRIGGERS
PL/SQL TRIGGERS
 
MySQL Stored Procedures: Building High Performance Web Applications
MySQL Stored Procedures: Building High Performance Web ApplicationsMySQL Stored Procedures: Building High Performance Web Applications
MySQL Stored Procedures: Building High Performance Web Applications
 
Sql server ___________session_18(stored procedures)
Sql server  ___________session_18(stored procedures)Sql server  ___________session_18(stored procedures)
Sql server ___________session_18(stored procedures)
 
An Introduction To PostgreSQL Triggers
An Introduction To PostgreSQL TriggersAn Introduction To PostgreSQL Triggers
An Introduction To PostgreSQL Triggers
 
Tony Jambu (obscure) tools of the trade for tuning oracle sq ls
Tony Jambu   (obscure) tools of the trade for tuning oracle sq lsTony Jambu   (obscure) tools of the trade for tuning oracle sq ls
Tony Jambu (obscure) tools of the trade for tuning oracle sq ls
 
Tony jambu (obscure) tools of the trade for tuning oracle sq ls
Tony jambu   (obscure) tools of the trade for tuning oracle sq lsTony jambu   (obscure) tools of the trade for tuning oracle sq ls
Tony jambu (obscure) tools of the trade for tuning oracle sq ls
 

Semelhante a Sql storeprocedure

Intro to tsql unit 14
Intro to tsql   unit 14Intro to tsql   unit 14
Intro to tsql unit 14Syed Asrarali
 
Stored procedures by thanveer danish melayi
Stored procedures by thanveer danish melayiStored procedures by thanveer danish melayi
Stored procedures by thanveer danish melayiMuhammed Thanveer M
 
05_DP_300T00A_Optimize.pptx
05_DP_300T00A_Optimize.pptx05_DP_300T00A_Optimize.pptx
05_DP_300T00A_Optimize.pptxKareemBullard1
 
Acutate - Using Stored Procedure
Acutate - Using Stored ProcedureAcutate - Using Stored Procedure
Acutate - Using Stored ProcedureAishwarya Savant
 
NoCOUG Presentation on Oracle RAT
NoCOUG Presentation on Oracle RATNoCOUG Presentation on Oracle RAT
NoCOUG Presentation on Oracle RATHenryBowers
 
Instrumenting plugins for Performance Schema
Instrumenting plugins for Performance SchemaInstrumenting plugins for Performance Schema
Instrumenting plugins for Performance SchemaMark Leith
 
Practical catalyst
Practical catalystPractical catalyst
Practical catalystdwm042
 
SQL Server with CSharp WinForms.pdf
SQL Server with CSharp WinForms.pdfSQL Server with CSharp WinForms.pdf
SQL Server with CSharp WinForms.pdfMona686896
 
Power shell examples_v4
Power shell examples_v4Power shell examples_v4
Power shell examples_v4JoeDinaso
 
SQL Server Performance Tuning with DMVs
SQL Server Performance Tuning with DMVsSQL Server Performance Tuning with DMVs
SQL Server Performance Tuning with DMVsFranklin Yamamoto
 
Oracle Sql Tuning
Oracle Sql TuningOracle Sql Tuning
Oracle Sql TuningChris Adkin
 
jBPM5 Community Training Module 4: jBPM5 APIs Overview + Hands On
jBPM5 Community Training Module 4: jBPM5 APIs Overview + Hands OnjBPM5 Community Training Module 4: jBPM5 APIs Overview + Hands On
jBPM5 Community Training Module 4: jBPM5 APIs Overview + Hands OnMauricio (Salaboy) Salatino
 
Sql Automation 20090610
Sql Automation 20090610Sql Automation 20090610
Sql Automation 20090610livingco
 
Performance Instrumentation for PL/SQL: When, Why, How
Performance Instrumentation for PL/SQL: When, Why, HowPerformance Instrumentation for PL/SQL: When, Why, How
Performance Instrumentation for PL/SQL: When, Why, HowKaren Morton
 
Salesforce Batch processing - Atlanta SFUG
Salesforce Batch processing - Atlanta SFUGSalesforce Batch processing - Atlanta SFUG
Salesforce Batch processing - Atlanta SFUGvraopolisetti
 
Stored procedure Notes By Durgesh Singh
Stored procedure Notes By Durgesh SinghStored procedure Notes By Durgesh Singh
Stored procedure Notes By Durgesh Singhimdurgesh
 
Data Seeding via Parameterized API Requests
Data Seeding via Parameterized API RequestsData Seeding via Parameterized API Requests
Data Seeding via Parameterized API RequestsRapidValue
 

Semelhante a Sql storeprocedure (20)

Intro to tsql unit 14
Intro to tsql   unit 14Intro to tsql   unit 14
Intro to tsql unit 14
 
Stored procedure
Stored procedureStored procedure
Stored procedure
 
QSpiders - Installation and Brief Dose of Load Runner
QSpiders - Installation and Brief Dose of Load RunnerQSpiders - Installation and Brief Dose of Load Runner
QSpiders - Installation and Brief Dose of Load Runner
 
Stored procedures by thanveer danish melayi
Stored procedures by thanveer danish melayiStored procedures by thanveer danish melayi
Stored procedures by thanveer danish melayi
 
05_DP_300T00A_Optimize.pptx
05_DP_300T00A_Optimize.pptx05_DP_300T00A_Optimize.pptx
05_DP_300T00A_Optimize.pptx
 
Acutate - Using Stored Procedure
Acutate - Using Stored ProcedureAcutate - Using Stored Procedure
Acutate - Using Stored Procedure
 
NoCOUG Presentation on Oracle RAT
NoCOUG Presentation on Oracle RATNoCOUG Presentation on Oracle RAT
NoCOUG Presentation on Oracle RAT
 
Instrumenting plugins for Performance Schema
Instrumenting plugins for Performance SchemaInstrumenting plugins for Performance Schema
Instrumenting plugins for Performance Schema
 
Practical catalyst
Practical catalystPractical catalyst
Practical catalyst
 
SQL Server with CSharp WinForms.pdf
SQL Server with CSharp WinForms.pdfSQL Server with CSharp WinForms.pdf
SQL Server with CSharp WinForms.pdf
 
Sherlock holmes for dba’s
Sherlock holmes for dba’sSherlock holmes for dba’s
Sherlock holmes for dba’s
 
Power shell examples_v4
Power shell examples_v4Power shell examples_v4
Power shell examples_v4
 
SQL Server Performance Tuning with DMVs
SQL Server Performance Tuning with DMVsSQL Server Performance Tuning with DMVs
SQL Server Performance Tuning with DMVs
 
Oracle Sql Tuning
Oracle Sql TuningOracle Sql Tuning
Oracle Sql Tuning
 
jBPM5 Community Training Module 4: jBPM5 APIs Overview + Hands On
jBPM5 Community Training Module 4: jBPM5 APIs Overview + Hands OnjBPM5 Community Training Module 4: jBPM5 APIs Overview + Hands On
jBPM5 Community Training Module 4: jBPM5 APIs Overview + Hands On
 
Sql Automation 20090610
Sql Automation 20090610Sql Automation 20090610
Sql Automation 20090610
 
Performance Instrumentation for PL/SQL: When, Why, How
Performance Instrumentation for PL/SQL: When, Why, HowPerformance Instrumentation for PL/SQL: When, Why, How
Performance Instrumentation for PL/SQL: When, Why, How
 
Salesforce Batch processing - Atlanta SFUG
Salesforce Batch processing - Atlanta SFUGSalesforce Batch processing - Atlanta SFUG
Salesforce Batch processing - Atlanta SFUG
 
Stored procedure Notes By Durgesh Singh
Stored procedure Notes By Durgesh SinghStored procedure Notes By Durgesh Singh
Stored procedure Notes By Durgesh Singh
 
Data Seeding via Parameterized API Requests
Data Seeding via Parameterized API RequestsData Seeding via Parameterized API Requests
Data Seeding via Parameterized API Requests
 

Último

Transaction Management in Database Management System
Transaction Management in Database Management SystemTransaction Management in Database Management System
Transaction Management in Database Management SystemChristalin Nelson
 
How to Add Barcode on PDF Report in Odoo 17
How to Add Barcode on PDF Report in Odoo 17How to Add Barcode on PDF Report in Odoo 17
How to Add Barcode on PDF Report in Odoo 17Celine George
 
What is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPWhat is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPCeline George
 
4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptx4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptxmary850239
 
Daily Lesson Plan in Mathematics Quarter 4
Daily Lesson Plan in Mathematics Quarter 4Daily Lesson Plan in Mathematics Quarter 4
Daily Lesson Plan in Mathematics Quarter 4JOYLYNSAMANIEGO
 
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITYISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITYKayeClaireEstoconing
 
Active Learning Strategies (in short ALS).pdf
Active Learning Strategies (in short ALS).pdfActive Learning Strategies (in short ALS).pdf
Active Learning Strategies (in short ALS).pdfPatidar M
 
Barangay Council for the Protection of Children (BCPC) Orientation.pptx
Barangay Council for the Protection of Children (BCPC) Orientation.pptxBarangay Council for the Protection of Children (BCPC) Orientation.pptx
Barangay Council for the Protection of Children (BCPC) Orientation.pptxCarlos105
 
Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...Seán Kennedy
 
Activity 2-unit 2-update 2024. English translation
Activity 2-unit 2-update 2024. English translationActivity 2-unit 2-update 2024. English translation
Activity 2-unit 2-update 2024. English translationRosabel UA
 
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdfGrade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdfJemuel Francisco
 
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17Celine George
 
4.16.24 Poverty and Precarity--Desmond.pptx
4.16.24 Poverty and Precarity--Desmond.pptx4.16.24 Poverty and Precarity--Desmond.pptx
4.16.24 Poverty and Precarity--Desmond.pptxmary850239
 
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATIONTHEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATIONHumphrey A Beña
 
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxMULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxAnupkumar Sharma
 
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptx
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptxQ4-PPT-Music9_Lesson-1-Romantic-Opera.pptx
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptxlancelewisportillo
 
Integumentary System SMP B. Pharm Sem I.ppt
Integumentary System SMP B. Pharm Sem I.pptIntegumentary System SMP B. Pharm Sem I.ppt
Integumentary System SMP B. Pharm Sem I.pptshraddhaparab530
 
Concurrency Control in Database Management system
Concurrency Control in Database Management systemConcurrency Control in Database Management system
Concurrency Control in Database Management systemChristalin Nelson
 

Último (20)

Transaction Management in Database Management System
Transaction Management in Database Management SystemTransaction Management in Database Management System
Transaction Management in Database Management System
 
How to Add Barcode on PDF Report in Odoo 17
How to Add Barcode on PDF Report in Odoo 17How to Add Barcode on PDF Report in Odoo 17
How to Add Barcode on PDF Report in Odoo 17
 
What is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPWhat is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERP
 
4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptx4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptx
 
YOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptx
YOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptxYOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptx
YOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptx
 
Daily Lesson Plan in Mathematics Quarter 4
Daily Lesson Plan in Mathematics Quarter 4Daily Lesson Plan in Mathematics Quarter 4
Daily Lesson Plan in Mathematics Quarter 4
 
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITYISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
 
Active Learning Strategies (in short ALS).pdf
Active Learning Strategies (in short ALS).pdfActive Learning Strategies (in short ALS).pdf
Active Learning Strategies (in short ALS).pdf
 
Barangay Council for the Protection of Children (BCPC) Orientation.pptx
Barangay Council for the Protection of Children (BCPC) Orientation.pptxBarangay Council for the Protection of Children (BCPC) Orientation.pptx
Barangay Council for the Protection of Children (BCPC) Orientation.pptx
 
Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...
 
Raw materials used in Herbal Cosmetics.pptx
Raw materials used in Herbal Cosmetics.pptxRaw materials used in Herbal Cosmetics.pptx
Raw materials used in Herbal Cosmetics.pptx
 
Activity 2-unit 2-update 2024. English translation
Activity 2-unit 2-update 2024. English translationActivity 2-unit 2-update 2024. English translation
Activity 2-unit 2-update 2024. English translation
 
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdfGrade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
 
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
 
4.16.24 Poverty and Precarity--Desmond.pptx
4.16.24 Poverty and Precarity--Desmond.pptx4.16.24 Poverty and Precarity--Desmond.pptx
4.16.24 Poverty and Precarity--Desmond.pptx
 
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATIONTHEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
 
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxMULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
 
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptx
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptxQ4-PPT-Music9_Lesson-1-Romantic-Opera.pptx
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptx
 
Integumentary System SMP B. Pharm Sem I.ppt
Integumentary System SMP B. Pharm Sem I.pptIntegumentary System SMP B. Pharm Sem I.ppt
Integumentary System SMP B. Pharm Sem I.ppt
 
Concurrency Control in Database Management system
Concurrency Control in Database Management systemConcurrency Control in Database Management system
Concurrency Control in Database Management system
 

Sql storeprocedure

  • 1. PRESENTATION STORE PROCEDURE Presented By – Prabhu P
  • 2.
  • 3. Difference between SP and Function
  • 4. How to create a store procedure
  • 6.
  • 7. What is store procedure? A stored procedure is a set of SQL commands that has been compiled and stored on the database server. Once the stored procedure has been "stored", client applications can execute the stored procedure over and over again without sending it to the database server again and without compiling it again. Stored procedures improve performance by reducing network traffic and CPU load.
  • 8.
  • 9. Avoidance of network traffic
  • 10. Encapsulation of business logic
  • 11. Delegation of access-rights
  • 12.
  • 13. Syntax Of Store ProcedureWith Parameter -- ============================================= -- Author: <Author,,Name> -- Create date: <Create Date,,> -- Description:<Description,,> -- ============================================= Create Proc SP_Name ( Param1 DataType, param2 DataType, Param3 DataType, . . . ParamnDataType ) As Begin Body Of Store Procedure End
  • 14. Implementation: -- ============================================= -- Author: <Author: XYZ> -- Create date: <Create Date:23/06/2010> -- Description: < Used to retrieve all information of an employee Information of from the Table ‘EmployeeInfo’ according to supplied Employee ID> -- ============================================= Create Proc SP_FetchSpecificEmployeeInfo ( EmpIdverchar(50) ) As Begin Select * from EmployeeInfo where EmployeeID= EmpId End
  • 15. Syntax Of Store ProcedureWith out Parameter -- ============================================= -- Author: <Author,,Name> -- Create date: <Create Date,,> -- Description:<Description,,> -- ============================================= Create Proc SP_Name As Begin Body Of Store Procedure End
  • 16. Implemetaion -- ============================================= -- Author: <Author: XYZ> -- Create date: <Create Date:23/06/2010> -- Description: < Used to retrieve all information of the table ‘EmployeeInfo’ without any Condition> -- ============================================= Create Proc SP_FetchAllEmployeeInfo As Begin Select * from EmployeeInfo End
  • 17. Using SP How To Insert Information -- ============================================= -- Author: < XYZ> -- Create date: <23/06/2010> -- Description: < Used To Insert Employee Information > -- ============================================= CREATE proc SP_InsertEmployeeInfo ( @ID varchar(20) , @Name varchar (50) , @Pin varchar(20), @Email varchar(50), @MobileNovarchar(20), @PhoneNovarchar(20), @MailingAddrvarchar(500) , @ParmanentAddrVarchar(500) , @Sex varchar(10) , @JoingDatesmalldatetime , @Post varchar(50) )
  • 18. AS Begin if exists(Select ID From EmployeeInfo Where ID = @ID) Begin return 0 End else Begin Insert into EmployeeInfo ( ID ,Name ,Pin ,Email ,MobileNo ,PhoneNo ,MailingAddr ,ParmanentAddr ,Sex ,JoingDate ,Post )
  • 19. values ( @ID ,@Name ,@Pin ,@Email ,@MobileNo ,@PhoneNo ,@MailingAddr ,@ParmanentAddr ,@Sex ,@JoingDate ,@Post ) End Begin return 1 End End
  • 20. Using SP How To Update Information -- ============================================= -- Author: < XYZ> -- Create date: <3/06/2010> -- Description: <Used To Update Record Of EmployeeInfo Table > -- ============================================= CREATE proc SP_UpdateEmployeeInfo ( @ID varchar(20) , @Name varchar (50) , @Pin varchar(20), @Email varchar(50), @MobileNovarchar(20), @PhoneNovarchar(20), @MailingAddrvarchar(500) , @ParmanentAddrVarchar(500) , @Sex varchar(10) , @JoingDatesmalldatetime , @Post varchar(50) )
  • 21. AS Begin if not exists(select id from EmployeeInfo where ID = @ID) Begin return 0 End else Begin Update EmployeeInfo set Name =@Name ,Pin =@Pin ,Email =@Email ,MobileNo =@MobileNo ,PhoneNo =@PhoneNo ,MailingAddr = @MailingAddr ,ParmanentAddr =@ParmanentAddr ,Sex =@Sex ,JoingDate =@JoingDate ,Post =@Post where ID =@ID return 1 End End
  • 22. Using SP How TO Delete Record -- ============================================= -- Author: < XYZ> -- Create date: <3/06/2010> -- Description: <Used To Delete Record From EmployeeInfo Table > -- ============================================= CREATE PROC SP_DeleteEmployeeInfo ( @id varchar(20) ) AS Begin if not exists(select id from EmployeeInfo where id = @id) Begin return 0 End else
  • 23. Begin if exists(select * from EmployeeInfo where id = @id and DeleteStatus = 0) Begin return 1 End else Begin delete from EmployeeInfo where id = @id return 2 End End End
  • 24.
  • 25.
  • 27. EXEC SP_NAME PARAMETER_lIST
  • 28. Implementation EXEC SP_FetchAllEmployeeInfo ‘001’
  • 29. How To Perform Execute SP
  • 30. sysobjects Name, type, etc. syscomments Text of object syscolumns Parameter list sysdepEnds Object depEndencies Parsing Creation Resolution Resolution* Execution(first timeor recompile) Optimization Compiled plan placed inunified cache Compilation Processing of Stored Procedures
  • 31.
  • 32. The create will succeed even if the objects do not exist
  • 33. Procedures called that do not exist generate error Cannot add rows to sysdepEnds for the current stored procedure because it depEnds on the missing object 'missingobjectname'. The stored procedure will still be created. Benefit: Recursion is allowed!
  • 34. Storing and Executing Procedures When you create a stored procedure, the server stores the text of the procedure in the syscomments table of the current database. In addition, form of the procedure, called a query tree , in the sysprocedures table. The server uses the query tree to create a query plan and then execute.
  • 35. Building the Query Tree: Resolution The process of building a query tree is called resolution. This process parses the SQL into a more efficient format and resolves all objects representations. For example, table names are resolved into their object IDs and column names are resolved into their column IDs.
  • 36.
  • 37. Statistics for each table and index referenced • in the procedure•The values of any parameters passed to the procedure on the first execution.
  • 38. Multiple Users and the Query Plan Stored procedures are reusable, not reentrant. This means that only one user at a time can execute a given copy of a procedure's query plan. the same procedure at the same time, Adaptive Server creates an additional query plan based on the parameters used in the later execution. procedure, the query plan is available in cache for reuse by anyone with execute permissions. If the server must generate a second query plan for a stored procedure, there is no guarantee that it is the same as the first.
  • 39.
  • 40. Advantage 2: Stored procedures are tunable
  • 41.