Skip to content

DEFAULT

CREATE TABLE Employees (
ID INT,
Name VARCHAR(20),
HasInsurance TINYINT DEFAULT 1
);
INSERT INTO Employees (ID, Name) VALUES (1, 'John');
SELECT * FROM Employees;
+------+-------+--------------+
| ID | Name | HasInsurance |
+------+-------+--------------+
| 1 | John | 1 |
+------+-------+--------------+

In this example, a new table named ‘Employees’ is created with three columns ‘ID’, ‘Name’, and ‘HasInsurance’. The ‘HasInsurance’ column has a default value of 1. Then, a new record is added where only the ‘ID’ and ‘Name’ values are specified. However, when all records are selected from the table, we see that the ‘HasInsurance’ field for John contains the default value of 1, since no particular value was specified during the row ‘John’ insertion.