SlideShare uma empresa Scribd logo
1 de 32
PRESENTATION  STORE PROCEDURE Presented By –  	Amin Uddin
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? ,[object Object],	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
Implementation       	EXEC    SP_FetchAllEmployeeInfo   ‘001’
How To Perform Execute SP
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
Initial Steps ,[object Object]
The create will succeed even if the objects do not exist

Mais conteúdo relacionado

Mais procurados

5. stored procedure and functions
5. stored procedure and functions5. stored procedure and functions
5. stored procedure and functionsAmrit Kaur
 
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
 
Procedures and triggers in SQL
Procedures and triggers in SQLProcedures and triggers in SQL
Procedures and triggers in SQLVikash Sharma
 
Intro to tsql unit 12
Intro to tsql   unit 12Intro to tsql   unit 12
Intro to tsql unit 12Syed Asrarali
 
Intro to tsql unit 15
Intro to tsql   unit 15Intro to tsql   unit 15
Intro to tsql unit 15Syed Asrarali
 
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
 
Oracle database performance tuning
Oracle database performance tuningOracle database performance tuning
Oracle database performance tuningAbishek V S
 
Intro to tsql unit 6
Intro to tsql   unit 6Intro to tsql   unit 6
Intro to tsql unit 6Syed Asrarali
 
7\9 SSIS 2008R2_Training - Script Task
7\9 SSIS 2008R2_Training - Script Task7\9 SSIS 2008R2_Training - Script Task
7\9 SSIS 2008R2_Training - Script TaskPramod Singla
 
SQL Server Tuning to Improve Database Performance
SQL Server Tuning to Improve Database PerformanceSQL Server Tuning to Improve Database Performance
SQL Server Tuning to Improve Database PerformanceMark Ginnebaugh
 
SQL Server Optimization Checklist
SQL Server Optimization ChecklistSQL Server Optimization Checklist
SQL Server Optimization ChecklistGrant Fritchey
 
Oracle Oracle Performance Tuning
Oracle Oracle Performance Tuning Oracle Oracle Performance Tuning
Oracle Oracle Performance Tuning Kernel Training
 

Mais procurados (20)

5. stored procedure and functions
5. stored procedure and functions5. stored procedure and functions
5. stored procedure and functions
 
Stored procedure in sql server
Stored procedure in sql serverStored procedure in sql server
Stored procedure in sql server
 
Triggers and Stored Procedures
Triggers and Stored ProceduresTriggers and Stored Procedures
Triggers and Stored Procedures
 
Database Testing
Database TestingDatabase Testing
Database Testing
 
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
 
Procedures and triggers in SQL
Procedures and triggers in SQLProcedures and triggers in SQL
Procedures and triggers in SQL
 
Intro to tsql
Intro to tsqlIntro to tsql
Intro to tsql
 
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 15
Intro to tsql   unit 15Intro to tsql   unit 15
Intro to tsql unit 15
 
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
 
Oracle database performance tuning
Oracle database performance tuningOracle database performance tuning
Oracle database performance tuning
 
Performance tuning in sql server
Performance tuning in sql serverPerformance tuning in sql server
Performance tuning in sql server
 
Intro to tsql unit 6
Intro to tsql   unit 6Intro to tsql   unit 6
Intro to tsql unit 6
 
7\9 SSIS 2008R2_Training - Script Task
7\9 SSIS 2008R2_Training - Script Task7\9 SSIS 2008R2_Training - Script Task
7\9 SSIS 2008R2_Training - Script Task
 
SQL Server Tuning to Improve Database Performance
SQL Server Tuning to Improve Database PerformanceSQL Server Tuning to Improve Database Performance
SQL Server Tuning to Improve Database Performance
 
SQL Server Optimization Checklist
SQL Server Optimization ChecklistSQL Server Optimization Checklist
SQL Server Optimization Checklist
 
Less11 Security
Less11 SecurityLess11 Security
Less11 Security
 
Oracle Oracle Performance Tuning
Oracle Oracle Performance Tuning Oracle Oracle Performance Tuning
Oracle Oracle Performance Tuning
 

Destaque

Areglado Exposicion
Areglado ExposicionAreglado Exposicion
Areglado Exposicioncarolina
 
Adicción o Libertad. El bienestar emocional y las adicciones
Adicción o Libertad. El bienestar emocional y las adiccionesAdicción o Libertad. El bienestar emocional y las adicciones
Adicción o Libertad. El bienestar emocional y las adiccionesLeocadio Martin Borges
 
Strategische inzet ict 100610
Strategische inzet ict 100610Strategische inzet ict 100610
Strategische inzet ict 100610Cees Corstanje
 
Augmented Reality Overview
Augmented Reality OverviewAugmented Reality Overview
Augmented Reality OverviewDamiano Povoleri
 
South Africa
South AfricaSouth Africa
South AfricaPorrenti
 
Presentatie szigetonderzoek
Presentatie szigetonderzoekPresentatie szigetonderzoek
Presentatie szigetonderzoekEveliendeJong
 
Entertainmentofthe80s
Entertainmentofthe80sEntertainmentofthe80s
Entertainmentofthe80sarmadilloxx
 
Peace%20 building%20activites%20to%20faster%20peace%20culture%20in%20schools[1]
Peace%20 building%20activites%20to%20faster%20peace%20culture%20in%20schools[1]Peace%20 building%20activites%20to%20faster%20peace%20culture%20in%20schools[1]
Peace%20 building%20activites%20to%20faster%20peace%20culture%20in%20schools[1]JRNRV Udaipur
 
Mobile Micro Learning_Catalysts For Change Zone of Future Innovtion
Mobile Micro Learning_Catalysts For Change Zone of Future InnovtionMobile Micro Learning_Catalysts For Change Zone of Future Innovtion
Mobile Micro Learning_Catalysts For Change Zone of Future InnovtionInstitute for the Future
 
Escola Estadual Ari Griesang
Escola Estadual Ari GriesangEscola Estadual Ari Griesang
Escola Estadual Ari GriesangLucena
 
Catalysts for Change - Zones of Future Innovation Project Overview
Catalysts for Change - Zones of Future Innovation Project Overview Catalysts for Change - Zones of Future Innovation Project Overview
Catalysts for Change - Zones of Future Innovation Project Overview Institute for the Future
 
3rd Party Inspection
3rd Party Inspection3rd Party Inspection
3rd Party Inspectionqaqcpipeman
 
ME 10 FAMOUSE NEW ZELANDEZ
ME 10 FAMOUSE NEW ZELANDEZME 10 FAMOUSE NEW ZELANDEZ
ME 10 FAMOUSE NEW ZELANDEZMaddie
 

Destaque (20)

Areglado Exposicion
Areglado ExposicionAreglado Exposicion
Areglado Exposicion
 
Adicción o Libertad. El bienestar emocional y las adicciones
Adicción o Libertad. El bienestar emocional y las adiccionesAdicción o Libertad. El bienestar emocional y las adicciones
Adicción o Libertad. El bienestar emocional y las adicciones
 
Strategische inzet ict 100610
Strategische inzet ict 100610Strategische inzet ict 100610
Strategische inzet ict 100610
 
Augmented Reality Overview
Augmented Reality OverviewAugmented Reality Overview
Augmented Reality Overview
 
Coffee & break i+d+i
Coffee & break i+d+iCoffee & break i+d+i
Coffee & break i+d+i
 
South Africa
South AfricaSouth Africa
South Africa
 
Olivia 2009
Olivia 2009Olivia 2009
Olivia 2009
 
Presentatie szigetonderzoek
Presentatie szigetonderzoekPresentatie szigetonderzoek
Presentatie szigetonderzoek
 
Entertainmentofthe80s
Entertainmentofthe80sEntertainmentofthe80s
Entertainmentofthe80s
 
Peace%20 building%20activites%20to%20faster%20peace%20culture%20in%20schools[1]
Peace%20 building%20activites%20to%20faster%20peace%20culture%20in%20schools[1]Peace%20 building%20activites%20to%20faster%20peace%20culture%20in%20schools[1]
Peace%20 building%20activites%20to%20faster%20peace%20culture%20in%20schools[1]
 
Mobile Micro Learning_Catalysts For Change Zone of Future Innovtion
Mobile Micro Learning_Catalysts For Change Zone of Future InnovtionMobile Micro Learning_Catalysts For Change Zone of Future Innovtion
Mobile Micro Learning_Catalysts For Change Zone of Future Innovtion
 
Escola Estadual Ari Griesang
Escola Estadual Ari GriesangEscola Estadual Ari Griesang
Escola Estadual Ari Griesang
 
Virtual Community Modeling
Virtual Community ModelingVirtual Community Modeling
Virtual Community Modeling
 
Catalysts for Change - Zones of Future Innovation Project Overview
Catalysts for Change - Zones of Future Innovation Project Overview Catalysts for Change - Zones of Future Innovation Project Overview
Catalysts for Change - Zones of Future Innovation Project Overview
 
Metrar group protocolo de iluminacion -----2015
Metrar group   protocolo de iluminacion -----2015Metrar group   protocolo de iluminacion -----2015
Metrar group protocolo de iluminacion -----2015
 
2010.01.01 inventarisatie
2010.01.01 inventarisatie 2010.01.01 inventarisatie
2010.01.01 inventarisatie
 
3rd Party Inspection
3rd Party Inspection3rd Party Inspection
3rd Party Inspection
 
Creativity with Chinese Characteristics
Creativity with Chinese CharacteristicsCreativity with Chinese Characteristics
Creativity with Chinese Characteristics
 
ME 10 FAMOUSE NEW ZELANDEZ
ME 10 FAMOUSE NEW ZELANDEZME 10 FAMOUSE NEW ZELANDEZ
ME 10 FAMOUSE NEW ZELANDEZ
 
Transcript (2)
Transcript (2)Transcript (2)
Transcript (2)
 

Semelhante a Advance Sql Server Store procedure Presentation

05_DP_300T00A_Optimize.pptx
05_DP_300T00A_Optimize.pptx05_DP_300T00A_Optimize.pptx
05_DP_300T00A_Optimize.pptxKareemBullard1
 
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
 
SQL Server 2008 Development for Programmers
SQL Server 2008 Development for ProgrammersSQL Server 2008 Development for Programmers
SQL Server 2008 Development for ProgrammersAdam Hutson
 
Intro to tsql unit 14
Intro to tsql   unit 14Intro to tsql   unit 14
Intro to tsql unit 14Syed Asrarali
 
Query Store and live Query Statistics
Query Store and live Query StatisticsQuery Store and live Query Statistics
Query Store and live Query StatisticsSolidQ
 
NoCOUG Presentation on Oracle RAT
NoCOUG Presentation on Oracle RATNoCOUG Presentation on Oracle RAT
NoCOUG Presentation on Oracle RATHenryBowers
 
Performance Tuning With Oracle ASH and AWR. Part 1 How And What
Performance Tuning With Oracle ASH and AWR. Part 1 How And WhatPerformance Tuning With Oracle ASH and AWR. Part 1 How And What
Performance Tuning With Oracle ASH and AWR. Part 1 How And Whatudaymoogala
 
Live Query Statistics & Query Store in SQL Server 2016
Live Query Statistics & Query Store in SQL Server 2016Live Query Statistics & Query Store in SQL Server 2016
Live Query Statistics & Query Store in SQL Server 2016Antonios Chatzipavlis
 
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
 
Oracle Sql Tuning
Oracle Sql TuningOracle Sql Tuning
Oracle Sql TuningChris Adkin
 
Instrumenting plugins for Performance Schema
Instrumenting plugins for Performance SchemaInstrumenting plugins for Performance Schema
Instrumenting plugins for Performance SchemaMark Leith
 
Acutate - Using Stored Procedure
Acutate - Using Stored ProcedureAcutate - Using Stored Procedure
Acutate - Using Stored ProcedureAishwarya Savant
 
MySQL Scaling Presentation
MySQL Scaling PresentationMySQL Scaling Presentation
MySQL Scaling PresentationTommy Falgout
 
Autonomous Transaction Processing (ATP): In Heavy Traffic, Why Drive Stick?
Autonomous Transaction Processing (ATP): In Heavy Traffic, Why Drive Stick?Autonomous Transaction Processing (ATP): In Heavy Traffic, Why Drive Stick?
Autonomous Transaction Processing (ATP): In Heavy Traffic, Why Drive Stick?Jim Czuprynski
 
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
 

Semelhante a Advance Sql Server Store procedure Presentation (20)

Stored procedure
Stored procedureStored procedure
Stored procedure
 
05_DP_300T00A_Optimize.pptx
05_DP_300T00A_Optimize.pptx05_DP_300T00A_Optimize.pptx
05_DP_300T00A_Optimize.pptx
 
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
 
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
 
SQL Server 2008 Development for Programmers
SQL Server 2008 Development for ProgrammersSQL Server 2008 Development for Programmers
SQL Server 2008 Development for Programmers
 
Intro to tsql unit 14
Intro to tsql   unit 14Intro to tsql   unit 14
Intro to tsql unit 14
 
Sherlock holmes for dba’s
Sherlock holmes for dba’sSherlock holmes for dba’s
Sherlock holmes for dba’s
 
Query Store and live Query Statistics
Query Store and live Query StatisticsQuery Store and live Query Statistics
Query Store and live Query Statistics
 
NoCOUG Presentation on Oracle RAT
NoCOUG Presentation on Oracle RATNoCOUG Presentation on Oracle RAT
NoCOUG Presentation on Oracle RAT
 
Performance Tuning With Oracle ASH and AWR. Part 1 How And What
Performance Tuning With Oracle ASH and AWR. Part 1 How And WhatPerformance Tuning With Oracle ASH and AWR. Part 1 How And What
Performance Tuning With Oracle ASH and AWR. Part 1 How And What
 
Live Query Statistics & Query Store in SQL Server 2016
Live Query Statistics & Query Store in SQL Server 2016Live Query Statistics & Query Store in SQL Server 2016
Live Query Statistics & Query Store in SQL Server 2016
 
Stored procedures by thanveer danish melayi
Stored procedures by thanveer danish melayiStored procedures by thanveer danish melayi
Stored procedures by thanveer danish melayi
 
Oracle Sql Tuning
Oracle Sql TuningOracle Sql Tuning
Oracle Sql Tuning
 
Instrumenting plugins for Performance Schema
Instrumenting plugins for Performance SchemaInstrumenting plugins for Performance Schema
Instrumenting plugins for Performance Schema
 
Acutate - Using Stored Procedure
Acutate - Using Stored ProcedureAcutate - Using Stored Procedure
Acutate - Using Stored Procedure
 
Php frameworks
Php frameworksPhp frameworks
Php frameworks
 
MySQL Scaling Presentation
MySQL Scaling PresentationMySQL Scaling Presentation
MySQL Scaling Presentation
 
Autonomous Transaction Processing (ATP): In Heavy Traffic, Why Drive Stick?
Autonomous Transaction Processing (ATP): In Heavy Traffic, Why Drive Stick?Autonomous Transaction Processing (ATP): In Heavy Traffic, Why Drive Stick?
Autonomous Transaction Processing (ATP): In Heavy Traffic, Why Drive Stick?
 
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
 
Oracle SQL Tuning
Oracle SQL TuningOracle SQL Tuning
Oracle SQL Tuning
 

Advance Sql Server Store procedure Presentation

  • 1. PRESENTATION STORE PROCEDURE Presented By – Amin Uddin
  • 2.
  • 3. Difference between SP and Function
  • 4. How to create a store procedure
  • 6.
  • 7.
  • 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.
  • 34.
  • 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.
  • 41. Saving plans for reuse is NOT always beneficial
  • 42.
  • 43. What options do you have Recompilation?
  • 44. How do you know you need to recompile?
  • 45. Do you want to recompile the entire procedure or only part of it?
  • 46.
  • 47. Procedure Re-resolution Like recompilation, re-resolution causes the generation of a new plan. In addition, re-resolution updates the existing query tree in the Re-resolution occurs when one of the tables changes in such a way that the query tree stored in the sysprocedures table may be invalid. IDs, or other parts of the table may have changed. In this case, Adaptive Server must rebuild some parts of the query tree. Adaptive Server re-resolves procedures after you do any of the following: • Execute the procedure for the first time after a load database. • Drop and re-create any table used or referenced by the procedure. • Drop and re-create a database containing a referenced table. • Bind or unbind a default or rule to a table referred to by a query in the procedure.
  • 48.
  • 49. When procedure returns widely varying results
  • 50. When the plan is not consistent
  • 51. EXECUTE … WITH RECOMPILE
  • 52. For testing and to determine if CREATE WITH RECOMPILE is necessary
  • 54. Forces all plans with regard to that object to be invalidated (note: this does not force recompilation on views even though a view name is supported)
  • 55. Statement Recompilation Dynamic String Execution or Modularized Code
  • 56. ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?