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
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.
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.
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)