Beruflich Dokumente
Kultur Dokumente
l=TjT07f87_9804984382
https://mva.microsoft.com/en-US/training-courses/developing-microsoft-sql-server-databases8482?l=QAfn5xXz_5204984382
https://mva.microsoft.com/en-US/training-courses/querying-microsoft-sql-server-2012-databasesjump-start-8241?l=WFbhCtJy_7204984382
https://www.mssqltips.com/sqlservertutorial/2250/graphical-query-plan-tutorial/
https://www.mssqltips.com/sqlservertutorial/3200/sql-server-query-performance-guidelinestutorial/
SQL OVERVIEW
Nilesh Desai
(OASIS)
What is SQL?
Structured Query
Language
Creating Table
Delete Table
Alter Table etc..
Insert
Delete
Update
Queries
- Simple selection
- Advance Query (Aggregation etc.)
- Nested Query
- Views
Agenda
What is scalability
Indexing
SQL Tuning Tips
What is Scalability?
Scalability
CPU Scalability:
The application is able to utilize additional processors and increase
business throughput linearly or close thereto .
What is Scalability?
Scalability
-
Data Scalability:
Processing 100,000 lines should take at most double the time of
processing 50,000 lines.
Response Time
Scalability
Non Scalable
Scalable
Number of User
Indexing
What is an Index?
Different Type of Indexes
When to user different type of indexes
How do Indexes works?
How to mange Indexes?
What is an Index?
Type of Index
Cluster Index
Non-cluster Index
Cluster Index
Non-Clustered Index
How Clustered
Indexes Work
True
Ali
True
Mathew
Ali
Page 140
George
..
False
Ali
Brown
George
Mathew
Sam
Hall
Mathew
Sam
Frank
James
Ota
William
Frank
James
Ricardo
William
Page
120
Page
Page
Page
100
110
130
Non-Clustered
Index
Ali
George
Ali
Mathew
Mathew
Sam
Ricardo>=
Mathew
True
Ricardo>=
Sam
False
Ali - 48057
George 48058
Mathew - 48064
Sam - 48065
Brown- 48052
Hall - 48059
Mathew - 48083
Sam - 48063
Frank - 48053
James - 48063
Ota - 48071
William - 48054
Frank - 48084
James - 48072
Ricardo - 48073
William - 48082
Brown - 48052
Ali - 4057
James- 48063
Frank- 48053 George- 48058 Mathew- 48064 James - 48072 Mathew- 48083
William - 48054 Hall - 48059
..
Leve
l
Ricardo, Rodriguez
..
Leaf
Level
Data
Page
What to Index
Large Table
Column that are frequently used in queries
Columns with strong selectivity
Columns used in aggregate functions
Column used in group by queries
Column used in order by queries
Small Tables
Columns that are rarely used in queries
Columns with poor selectivity
Tables with many modification, but few
actual queries
SQL Tuning
SQL Tips 1
WHERE Clauses
USE
SELECT region, AVG (loc_size) FROM location WHERE
region != SYDNEY AND region != PERTH GROUP BY region
Tips 3
Tips 4
JOIN Vs EXISTS Vs IN
Use an EXISTS when u want drive from the outer-query and you
want to perform a simple existences check based on the outer-rows.
Use an IN when you want to drive from the sub-queries.
Avoid joins that required the DISTINCT qualifier in the SELECT list
in queries which are used to determine information at the owner
end of a one to many relationship. The DISTINCT operator
cause to fetch all rows satisfying the table join and the sort and
filter out duplicate values. EXISTS is faster alternative because
the optimizer realizes when the subquery has been satisfied once,
there is no need to proceed further and the next matching raw can
be fetched.
Do Not Use
Tips 6
OR Operator
Do Not USE
USE
The specific topics that will be covered in this tip are as follows:
Query writing:
Use WHERE, JOIN, ORDER BY, SELECT Column Order When Creating Indexes
Use DELETE CASCADE Option to Handle Child Key Removal in Foreign Key Relationships
The order in which the tables in your queries are joined can have a dramatic effect on
how the query performs. If your query happens to join all the large tables first and
then joins to a smaller table later this can cause a lot of unnecessary processing by
the SQL engine.
Using functions as a part of any type of programming is usually a good practice as it
generally makes code more readable and allows you to use to use it over and over
again. This is also true for SQL queries except for the fact that there are cases when
running the same statement over and over again might not be the most efficient way
to get your result.
In almost all cases when we use the <> operator (or any other operator in conjunction
with the NOT operator, i.e.. NOT IN) index seeks will not be performed and instead a
table/index scan is required.
it's always best to use an equality operator, like = or IN, in you query if you want the
best performance possible.
.