How to Create a Table in SQLite with CREATE TABLE
A new SQLite database is empty. Before it can hold anything, it needs a table: a name, and the columns every row will have. This guide creates a books table with CREATE TABLE and checks what was created, with real output from SQLite 3.54.1.
Syntax
CREATE TABLE <table> (
<column> <type>,
<column> <type>
);
| Part | What it means |
|---|---|
<table> | The new table's name |
<column> <type> | One column: its name, then its type, such as TEXT, INTEGER, REAL or BLOB |
, | Separates the columns. There's none after the last one |
; | Ends the statement |
SQLite's CREATE TABLE documentation describes the command as the one that "is used to create a new table in an SQLite database."
Prerequisites
- The sqlite3 command-line shell. This guide uses SQLite 3.54.1. Run
sqlite3 --versionto see yours; the SQLite download page has the command-line tools for Windows, macOS and Linux.
Step 1: Write the Script
Save this as create_table.sql:
CREATE TABLE books (
title TEXT,
author TEXT,
pages INTEGER
);
PRAGMA table_info(books);

CREATE TABLE booksnames the new tablebooks.- Each line inside the parentheses is one column:
titleandauthorhold text,pagesholds whole numbers. PRAGMA table_info(books)lists the table's columns, so you can see what was created.
Step 2: Run It
In the folder that holds the script, run:
sqlite3 -table library.db ".read create_table.sql"
sqlite3 opens the database file library.db, and creates it when it isn't there. -table prints each result as a table, and .read runs the statements in the script. The command is the same in bash, zsh and PowerShell.
+-----+--------+---------+---------+------------+----+
| cid | name | type | notnull | dflt_value | pk |
+-----+--------+---------+---------+------------+----+
| 0 | title | TEXT | 0 | | 0 |
| 1 | author | TEXT | 0 | | 0 |
| 2 | pages | INTEGER | 0 | | 0 |
+-----+--------+---------+---------+------------+----+

library.db now holds a books table with three columns, numbered in the order they were written (cid 0 to 2), each with its type. The other columns are 0 or empty: none of the columns is required (notnull), has a default value (dflt_value) or belongs to the primary key (pk).
Common Mistakes
| Mistake | What happens | Do this instead |
|---|---|---|
A missing comma, title TEXT author TEXT, pages INTEGER | No error at all: SQLite made one column, title, with the type TEXT author TEXT, and no author column | Put a comma after every column except the last |
| A comma after the last column | Parse error ...: near ")": syntax error | Remove the comma before ) |
| Expecting SQLite to check the types | An INSERT put the text 'lots' into pages INTEGER, and it was stored as text | Add STRICT after the closing parenthesis, as in the FAQ below |
Troubleshooting
| Symptom | Likely cause | Fix |
|---|---|---|
Parse error near line 1 of create_table.sql: table books already exists | The script already ran on library.db | Delete library.db and run the script again, or write CREATE TABLE IF NOT EXISTS books |
FAQ
Can I run the script again without an error?
Yes. CREATE TABLE IF NOT EXISTS books (...) creates the table only when it isn't there yet, and does nothing otherwise: run twice, it gave no error.
How do I make SQLite check the column types?
Write STRICT after the closing parenthesis: CREATE TABLE books (...) STRICT;. Then the same INSERT of 'lots' into pages failed with cannot store TEXT value in INTEGER column books.pages. STRICT tables allow only the types INT, INTEGER, REAL, TEXT, BLOB and ANY.
Which types can a column have?
SQLite stores every value as one of five classes: NULL, INTEGER, REAL, TEXT and BLOB. A column's type is a preference, not a rule, unless the table is STRICT.
Conclusion
CREATE TABLE books (...) gave library.db a table with three typed columns, and PRAGMA table_info(books) showed them in order, ready for rows.
Additional Resources
- CREATE TABLE — the full syntax, constraints included.
- Datatypes In SQLite — storage classes and column types.
- STRICT Tables — tables that check their column types.
