The DEFAULT constraint in SQL is used to provide a default value for a column when no value is specified during INSERT. It helps ensure consistent data and avoids NULL where appropriate.
SQL Default Syntax
SQL
x
1
CREATE TABLE table_name (
2
column_name datatype DEFAULT default_value
3
);
SQL Default Example
SQL Default on Create Table
This query sets a default gender of ‘F’ in the PatientsWithGenderDefault table:
SQL
1
1
CREATE TABLE PatientsWithGenderDefault (
2
patient_id INTEGER PRIMARY KEY,
3
first_name VARCHAR(50) NOT NULL,
4
last_name VARCHAR(50) NOT NULL,
5
dob DATE NOT NULL,
6
gender CHAR(1) DEFAULT 'F',
7
contact_number VARCHAR(15)
8
);

Now inserting a row without specifying gender will default it to ‘F’.
SQL Default on Alter Table
SQLite supports adding new columns with default values via ALTER TABLE, but only when the new column is added.
This query demonstrates adding a new column with a default value, :
SQL
1
1
ALTER TABLE Patients
2
ADD COLUMN nationality TEXT DEFAULT 'Unknown';

This adds a nationality column to the existing Patients table and sets its default value to ‘Unknown’.
SQL Default Drop a Default Constraint
SQLite does not support dropping a default constraint directly.
If you need to change or remove a default:
- Create a new table without the
DEFAULT
- Copy data over
- Drop the old table
- Rename the new table