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

Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104misteraugie
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactPECB
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
 
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...RKavithamani
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...EduSkills OECD
 
URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppCeline George
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionSafetyChain Software
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphThiyagu K
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingTechSoup
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxmanuelaromero2013
 

Último (20)

Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
 
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
 
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website App
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory Inspection
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot Graph
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptx
 

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.