This SQLite post explains how to use the SQLite CREATE TABLE statement with syntax and examples.
The SQLite CREATE TABLE statement allows you to create and define a table.
The syntax for the CREATE TABLE statement in SQLite is:
CREATE TABLE table_name
(
column1 datatype [ NULL | NOT NULL ],
column2 datatype [ NULL | NOT NULL ],
...
);
The name of the table that you wish to create.
The columns that you wish to create in the table.
The data type for the column.
Let's look at a SQLite CREATE TABLE example.
CREATE TABLE employees
( employee_id INTEGER PRIMARY KEY AUTOINCREMENT,
last_name VARCHAR NOT NULL,
first_name VARCHAR,
hire_date DATE
);
This SQLite CREATE TABLE example creates a table called employees which has 4 columns and one primary key:
Next, let's create a table that has a DEFAULT VALUE.
CREATE TABLE products
( product_id INTEGER PRIMARY KEY AUTOINCREMENT,
product_name VARCHAR NOT NULL,
quantity INTEGER NOT NULL DEFAULT 0
);
This SQLite CREATE TABLE example creates a table called products which has 3 columns and one primary key: