Stilul SQL

SQL intermediar

Jasmin Ludolf

Data Science Content Developer, DataCamp

Formatarea SQL

  • Formatarea nu este obligatorie
  • Dar lipsa ei poate cauza probleme
select title, release_year, country from films limit 3
|title                                           |release_year|country|
|------------------------------------------------|------------|-------|
|Intolerance: Love's Struggle Throughout the Ages|1916        |USA    |
|Over the Hill to the Poorhouse                  |1920        |USA    |
|The Big Parade                                  |1925        |USA    |
SQL intermediar

Bune practici

SELECT title, release_year, country
FROM films 
LIMIT 3;
|title                                           |release_year|country|
|------------------------------------------------|------------|-------|
|Intolerance: Love's Struggle Throughout the Ages|1916        |USA    |
|Over the Hill to the Poorhouse                  |1920        |USA    |
|The Big Parade                                  |1925        |USA    |
  • Scrieți cuvintele cheie cu majuscule
  • Adăugați linii noi
SQL intermediar

Ghiduri de stil

SELECT  
    title, 
    release_year, 
    country
FROM films 
LIMIT 3;
|title                                           |release_year|country|
|------------------------------------------------|------------|-------|
|Intolerance: Love's Struggle Throughout the Ages|1916        |USA    |
|Over the Hill to the Poorhouse                  |1920        |USA    |
|The Big Parade                                  |1925        |USA    |
SQL intermediar

Ghiduri de stil

 

Ghidul de stil Holywell: https://www.sqlstyle.guide/

Secvență de mâzgălituri devenind o linie dreaptă

Scrieți cod clar și lizibil

SQL intermediar

Punct și virgulă

SELECT title, release_year, country
FROM films 
LIMIT 3;

 

  • Bună practică
  • Mai ușor de adaptat între variante SQL
  • Indică sfârșitul unei interogări
SQL intermediar

Gestionarea numelor de câmpuri nestandard

  • release year în loc de release_year
  • Puneți numele de câmpuri nestandard între ghilimele duble
SELECT title, "release year", country
FROM films 
LIMIT 3;
SQL intermediar

De ce formatăm?

  • Colaborare mai ușoară
  • Cod curat și lizibil
  • Aspect profesional
  • Mai ușor de înțeles
  • Mai ușor de depanat
SQL intermediar

Să exersăm!

SQL intermediar

Preparing Video For Download...