SQLite - Create tables
by
Jeremy Canfield |
Updated: February 13 2023
| SQLite articles
The create table command can be used to create a table. In this example, a table named "temp" is created.
~]$ sqlite3 /path/to/example.db
SQLite version 3.34.1 2021-01-20 14:10:07
Enter ".help" for usage hints.
sqlite> create table users (id INTEGER NOT NULL,date DATETIME,username VARCHAR(100) NOT NULL,password VARCHAR(100) NOT NULL,PRIMARY KEY (id),UNIQUE (id),UNIQUE (username));
Or like this, as a oneliner command.
~]$ sqlite3 /path/to/example.db "create table users (id INTEGER NOT NULL,date DATETIME,username VARCHAR(100) NOT NULL,password VARCHAR(100) NOT NULL,PRIMARY KEY (id),UNIQUE (id),UNIQUE (username));"
Assuming the table was successfully created, the .tables command should show that the table exists.
sqlite> .tables
users
And the .schema command can be used to list the columns in a table.
sqlite> .schema users
CREATE TABLE users (
id INTEGER NOT NULL,
date DATETIME,
username VARCHAR(100) NOT NULL,
password VARCHAR(100) NOT NULL,
PRIMARY KEY (id),
UNIQUE (id),
UNIQUE (username)
);
Did you find this article helpful?
If so, consider buying me a coffee over at