Presentation is loading. Please wait.

Presentation is loading. Please wait.

Query Optimization By Rick Mason, SeedChoices.com.

Similar presentations


Presentation on theme: "Query Optimization By Rick Mason, SeedChoices.com."— Presentation transcript:

1 Query Optimization By Rick Mason, SeedChoices.com

2 Just because you can do something in ColdFusion Doesn’t always mean ColdFusion is the best way to do it

3 Always have the database do as much of the work as possible - Ben Forta

4 First step : Create Indexes Greatest performance boost with the least effort MS Access automatically indexes primary keys and foreign keys SQL Server doesn’t – you must do it yourself

5 SQL Server indexes Clustered Non-Clustered

6 Clustered Indexes Mostly for tables primary key Only one clustered index per table Orders tables data in order you specify

7 Non-Clustered Indexes You can have multiple non-clustered indexes An important tool in query optimization All non-clustered indexes go through tables clustered index if one is available

8

9

10 Using SQL Server query analyzer

11 Second step: Stored procedures What is a stored procedure? Pre-compiled SQL statement residing in the database You can pass parameters in You can receive result sets(s) out

12 Why use stored procedures? Pre-compile once, use many times Stored procedure is a re-usable object Reduce network traffic Separate business rules and logic from presentation layer They’re faster

13 Writing stored procedures Create procedure[name] Input parameters Output parameters AS Declare local variables SQL statement

14

15 Stored procedure example

16 Calling stored procedures – Using CFQuery {CALL USP_CompanyProductList('#CompanyDistrictID#')}

17 Calling Stored Procedures - Using cfstoredproc <cfstoredproc procedure=“DealInv” Datasource=“MyData”> <cfprocparam type=“IN” Cfsql type = “CF_SQL_Integer” Value=‘#CompanyDistrictID#’>

18 You need to use cfstoredproc If you need more than one result set You’re using Oracle or DB2

19 Running a stored procedure CFQuery or CFStoredProc goes here Your query produced an error #Catch.Detail#

20 Stored procedure – Insert example Create Procedure InsPerson @PersonUserName varchar(20) @PersonPassword varchar(20) AS INSERT Into Person(PersonUserName, PersonPassword) Values(@PersonUserName, @PersonPassword) Select @@Identity AS PersonID

21 What about MS Access? CFStoredProc can call stored Access queries and pass variables CFQUERY CALL will run queries but not let you pass variables Make sure cfadministrator has execute remote procedures turned on for your data source

22

23 Calling a stored procedure in Access

24 Automating Stored Procedure Creation With the Stored Procedure Wizard ftp://ftp.productivityenhancement.com/storedprocwiz10.zip By the folks at ColdFusionTraining.com

25

26

27

28

29

30

31 Additional references Using Stored Procedures by Ian Rutherford in CF Dev. Journal – Oct, Dec 2001 & Feb, May 2002 Stored Procedures in Access by Charlie Arehart in CF Dev. Journal – Oct 1999 MS SQL Server 7 Administrators Guide by Ron Talmage – ISBN 0-7615-1389-2

32 Contact Rick@SeedChoices.com


Download ppt "Query Optimization By Rick Mason, SeedChoices.com."

Similar presentations


Ads by Google