We use cookies to enhance your experience on the site
CodeWorlds

Rules for writing queries

The Library's language has a few simple customs. Stick to them and your queries will always be readable.

The semicolon ends an order

We end every SQL command with a semicolon ";". It is a signal to the Library: "this is the whole order, you may run it".

1SELECT * FROM autorzy;

Letter case

SQL keywords (

SELECT
,
FROM
,
WHERE
...) can be written in lower or upper case - it makes no difference to the Library. By convention, however, we write them in UPPERCASE to distinguish them from column and table names:

1SELECT imie, nazwisko FROM czytelnicy;

Comments

Sometimes we want to leave a note in the margin of a scroll. A single-line comment starts with two dashes

--
:

1-- This query shows all authors
2SELECT * FROM autorzy;

The Library ignores comments - they are only for us, the scribes.

Whitespace

SQL does not care about spaces and new lines. These two queries are identical:

1SELECT tytul FROM ksiazki;
1SELECT tytul
2FROM ksiazki;

We usually split longer queries across lines - it is more readable that way.

Go to CodeWorlds