Stile SQL

SQL intermedio

Jasmin Ludolf

Data Science Content Developer, DataCamp

Formattazione SQL

  • La formattazione non è obbligatoria
  • Ma la mancanza può creare problemi
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 intermedio

Best practice

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    |
  • Metti in maiuscolo le keyword
  • Aggiungi nuove righe
SQL intermedio

Guide di stile

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 intermedio

Guide di stile

 

Guida di stile di Holywell: https://www.sqlstyle.guide/

Sequenza di scarabocchi che diventa una linea retta

Scrivi codice chiaro e leggibile

SQL intermedio

Punto e virgola

SELECT title, release_year, country
FROM films 
LIMIT 3;

 

  • Buona pratica
  • Più facile passare tra dialetti SQL
  • Indica la fine di una query
SQL intermedio

Gestire nomi di campo non standard

  • release year invece di release_year
  • Metti i nomi di campo non standard tra virgolette doppie
SELECT title, "release year", country
FROM films 
LIMIT 3;
SQL intermedio

Perché formattiamo?

  • Collaborazione più facile
  • Codice pulito e leggibile
  • Aspetto professionale
  • Più facile da capire
  • Più facile da fare debug
SQL intermedio

Vamos praticar!

SQL intermedio

Preparing Video For Download...