SELECT sonrası sorgulama

SQL Server'da Sorgu Performansını İyileştirme

Dean Smith

Founder, Atamai Analytics

SELECT’ten sonra işleme sırası

1.  FROM

2. ON
3. JOIN
4. WHERE
5. GROUP BY
6. HAVING
7. SELECT
8. DISTINCT
9. ORDER BY
10. TOP
SQL Server'da Sorgu Performansını İyileştirme

Her zaman hepsi iyi değildir

SELECT *
FROM PlayerStats;

SELECT * veri inceleme için iyidir, ancak performans açısından kötü olabilir

PlayerName Team Position ... ...
Alex Abrines OKC SG ... ...
Quincy Acy BRK PF ... ...
Steven Adams OKC C ... ...
Bam Adebayo MIA C ... ...
... ... ... ... ...
SQL Server'da Sorgu Performansını İyileştirme

Gereken kadarı en iyisidir

SELECT PlayerName, 
        Team, 
        TotalPoints
FROM PlayerStats;

Yalnızca gerekli sütunları seçin

PlayerName Team TotalPoints
Alex Abrines OKC 353
Quincy Acy BRK 411
Steven Adams OKC 1056
Bam Adebayo MIA 477
... ... ...
SQL Server'da Sorgu Performansını İyileştirme

JOIN’de hepsi

SELECT * 
FROM Players p
  INNER JOIN PlayerStats ps
  ON ps.PlayerName = p.PlayerName;

Join’lerde SELECT *, birleştirilen sütunları yineler

PlayerName Age PlayerName Team ...
Alex Abrines 24 Alex Abrines OKC ...
Quincy Acy 27 Quincy Acy BRK ...
Steven Adams 24 Steven Adams OKC ...
Bam Adebayo 20 Bam Adebayo MIA ...
... ... ... ... ...
SQL Server'da Sorgu Performansını İyileştirme

JOIN’de gerekenler

SELECT p.PlayerName, 
       ps.Team, 
       p.Country, 
       ps.Position
FROM Players p
  INNER JOIN PlayerStats ps
  ON ps.PlayerName = p.PlayerName;

Döndürülecek sütunları ve geldikleri tabloları açıkça belirtin

PlayerName Country Team Position
Alex Abrines Spain OKC SG
Quincy Acy USA BRK PF
Steven Adams New Zealand OKC C
Bam Adebayo USA MIA C
... ... ... ...
SQL Server'da Sorgu Performansını İyileştirme

Üstteki satırlar (TOP)

SELECT TOP 5 PlayerName, 
        Team, 
        TotalPoints
FROM PlayerStats;
PlayerName Team TotalPoints
Alex Abrines OKC 353
Quincy Acy BRK 411
Steven Adams OKC 1056
Bam Adebayo MIA 477
Arron Afflalo ORL 179
SQL Server'da Sorgu Performansını İyileştirme

Yüzde ile TOP

SELECT TOP 1 PERCENT PlayerName, 
        Team, 
        TotalPoints
FROM PlayerStats;
PlayerName Team TotalPoints
Alex Abrines OKC 353
Quincy Acy BRK 411
Steven Adams OKC 1056
Bam Adebayo MIA 477
Arron Afflalo ORL 179
Cole Aldrich MIN 12
LaMarcus Aldridge SAS 1735
SQL Server'da Sorgu Performansını İyileştirme

Baş ya da son yoktur

SELECT TOP 5 PlayerName, 
        Team, 
        TotalPoints
FROM PlayerStats
ORDER BY TotalPoints DESC
PlayerName Team TotalPoints
LeBron James CLE 2251
James Harden HOU 2191
Anthony Davis NOP 2110
Russell Westbrook OKC 2028
Giannis Antetokounmpo MIL 2014
SQL Server'da Sorgu Performansını İyileştirme

Diğer satır sınırlayıcılar

Satır sınırlayıcı Sıralama ifadesi Veritabanı
TOP ORDER BY Microsoft SQL Server
ROWNUM ORDER BY Oracle
LIMIT ORDER BY PostgreSQL
SQL Server'da Sorgu Performansını İyileştirme

ORDER BY ne zaman kullanılır

Bir sorguda ORDER BY şunlar için kullanılır:

  • Veriyi incelemek için
  • Nihai sonuçların sıralanması için geçerli bir neden olduğunda
SQL Server'da Sorgu Performansını İyileştirme

Ayo berlatih!

SQL Server'da Sorgu Performansını İyileştirme

Preparing Video For Download...