SQL DEFAULT Keyword
SQL DEFAULT Keyword is a SQL statement in the DML Statements category. DEFAULT keyword inserts the column'\s default value. Can be used in INSERT statements explicitly. The syntax is INSERT INTO t VALUES (DEFAULT, 'value', DEFAULT);. It returns dEFAULT applied. A typical example: CREATE TABLE items ( id INT AUTO_INCREMENT PRIMARY KEY, name VARCHAR(100), created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, active BOOLEAN DEFAULT TRUE ); INSERT INTO items VALUES (DEFAULT, 'Widget', DEFAULT, DEFAULT); -- id: auto, name: Widget, created_at: NOW(), active: TRUE INSERT INTO items (name) VALUES ('Gadget'); -- Same result (omitted columns get defaults) -- UPDATE with DEFAULT: UPDATE items SET active = DEFAULT WHERE id = 1; -- Resets active to its default… A close relative is INSERT INTO, which inserts new rows into a table. A close relative is UPDATE, which modifies existing rows in a table. Always use WHERE to avoid updating all rows. A close relative is DELETE, which removes rows from a table. Always use WHERE to avoid deleting all rows.