SQLite DEFAULT Constraint
DEFAULT
DEFAULT gives a column a value when the insert does not give one.
Example
CREATE TABLE IF NOT EXISTS Persons (
PersonID INTEGER PRIMARY KEY,
Name TEXT,
City TEXT DEFAULT 'Oslo'
);
INSERT INTO Persons (Name) VALUES ('Tobias');
SELECT * FROM Persons;
Try it Yourself »
Default Date and Time
CURRENT_DATE, CURRENT_TIME and CURRENT_TIMESTAMP give the date and time when the record is inserted (in UTC):
Example
CREATE TABLE IF NOT EXISTS Notes (
NoteID INTEGER PRIMARY KEY,
Note TEXT,
Created TEXT DEFAULT CURRENT_TIMESTAMP
);
INSERT INTO Notes (Note) VALUES ('Buy milk');
SELECT * FROM Notes;
Try it Yourself »
Default From an Expression
The default can also be an expression in parentheses, like DEFAULT (date('now', '+14 days')).