Convention
Conventions are agreements made between developers to improve code readability. Typically, each team or project follows its own set of conventions.
In SQL, there is a fairly strong convention that many developers follow.
Capitalization
In SQL, it is recommended to write the names we define (identifiers) in lowercase and the words defined by SQL (keywords) in uppercase.
As a result, words we define like users or user_id are written in lowercase, while words like CREATE and TABLE are written in uppercase.
- Note: Mixing them will still work perfectly fine. It is simply not recommended.
Naming Convention
So, how should we name the identifiers we define?
Naming conventions can vary by database. While PostgreSQL doesn’t have a strict rule, snake_case is implicitly used by most developers.
- snake_case rules:
- All characters in lowercase: Use only lowercase letters, no capitals.
- Use underscores (
_) between words: Connect words with an underscore instead of using spaces. - Using numbers: You can use numbers, but it’s generally better to start with a letter.
Now, let’s look at Keys, a core concept for distinguishing data within a table.