DDL Table Creation

We have seen the language in action in the last exercise. Let's look closer:

CREATE TABLE test(id INT PRIMARY KEY, name VARCHAR(255));

This bit of DDL defines a table called test with two columns: one column called id, and another one called name. The id column has the type INT, which can store integer values. The name column, on the other hand, can store strings of a variable number of characters, up to a maximum length of 255.


It is customary to write all SQL keywords in uppercase. This, however, is only a convention, and SQL is case-agnostic.
Slightly contested, but still widespread is the convention to use lowercase for identifiers. SQL is case-agnostic here as well.

The id column is meant to store an identifier for the row. This is also called a key in databases. Identifiers should be unique within a table and adding the keywords PRIMARY KEY will make the database enforce this constraint.


Most databases can be forced to use identifiers with only the specified case. This is asking for trouble. 

There is a lot of standardization in SQL, but, unfortunately, each database has its quirks or extensions. For instance, the normal type for storing strings of characters is called VARCHAR2 in Oracle, and it cannot store empty strings, because empty strings are handled the same as the special NULL values.