0% found this document useful (0 votes)
6 views

SQL

The document discusses the impact of OUTER and INNER JOINs on result set sizes, recommending to perform INNER JOINs before LEFT JOINs for efficiency. It outlines common causes of slow-running queries and suggests solutions, such as creating indexes and specifying column names in SELECT statements. Additionally, it emphasizes the importance of using indexes for optimizing performance in SQL queries involving large datasets.

Uploaded by

yahsuD
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

SQL

The document discusses the impact of OUTER and INNER JOINs on result set sizes, recommending to perform INNER JOINs before LEFT JOINs for efficiency. It outlines common causes of slow-running queries and suggests solutions, such as creating indexes and specifying column names in SELECT statements. Additionally, it emphasizes the importance of using indexes for optimizing performance in SQL queries involving large datasets.

Uploaded by

yahsuD
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

SQL

1. A general rule of thumb is that OUTER JOINs cause the number of rows in a result set to
increase, while INNER JOINs cause the number of rows in a result set to decrease. Of course,
there are plenty of scenarios where the opposite is true as well, but it's more likely to work this
way than not. What you want to do is keep the size of the result set as small as possible for as
long as possible.
Since both joins match on the first table, changing up the order won't effect the accuracy
of the results. Therefore, you probably want to do the INNER JOIN before the LEFT
JOIN:

I have two tables: table1, table2. Table1 has 10 columns, table2 has 2 columns.
3
SELECT * FROM table1 AS T1 INNER JOIN table2 AS T2 ON T1.ID = T2.ID

I want to select all columns from table1 and only 1 column from table2. Is it possible to do that
without enumerating all columns from table1 ?

SELECT t1.*, t2.my_col FROM table1 AS T1 INNER JOIN table2 AS T2 ON T1.ID = T2.ID

Checklist for Analyzing Slow-Running Queries


There are a number of common reasons for slow-running queries and updates:

 Slow network communication.


 Inadequate memory in the server computer, or not enough memory available for SQL
Server.
 Lack of useful statistics
 Lack of useful indexes.
 Lack of useful indexed views.
 Lack of useful data striping.
 Lack of useful partitioning.

To increase performance of the query:

1.Create Index in the table.


2.Have a Primary key in the table while creating.
3.Use Joins instead of subqueries.
4.Instead of selcting "*" specify the Column names in the select statement.
Hi,

One of the best ways to increase query performance is to use indexes. You'll see a marked increase in
performance, especially in situations where you're dealing with hundreds of thousands of records in
the table you're querying. For instance, I had written code to join two tables in Paradox. One table had
1.5 million records in it and the other had maybe a few hundred. When run without indexes on either
table.

You can use Index Tuning Wizard to improve the performence in SQL Server.

If you perform regular joins between two or more tables in your queries, performance
will be optimized if each of the joined columns have their own indexes. This includes adding
indexes to the columns in each table used to join the tables. Generally speaking, a clustered
key is better than a non-clustered key for optimum JOIN performance. [6.5, 7.0,

You might also like