MySQL DEFAULT Expression
MySQL DEFAULT Expression is a SQL statement in the MySQL Specific category. MySQL 8.0.13+: DEFAULT values can be expressions, not just constants. Includes function calls and subqueries. The syntax is column type DEFAULT (expression). It returns expression default. A typical example: CREATE TABLE items ( id INT PRIMARY KEY AUTO_INCREMENT, name VARCHAR(100), created_at TIMESTAMP DEFAULT (NOW()), uuid VARCHAR(36) DEFAULT (UUID()), day_of_week INT DEFAULT (DAYOFWEEK(NOW())), random_val DECIMAL DEFAULT (RAND()) ); -- Previously, MySQL only allowed constants or CURRENT_TIMESTAMP -- Now supports any expression in parentheses INSERT INTO items (name) VALUES ('Widget'); -- Auto-fills: created_at=NOW(), uuid=random UUID, etc. -- PostgreSQL has supported this for longer: -- DEFAULT gen_random_uuid() -- DEFAULT NOW() -- DEFAULT… A close relative is AUTO_INCREMENT, which mySQL auto-generates sequential integer values for this column. Commonly used with PRIMARY KEY. A close relative is ENGINE, which specifies the MySQL storage engine. InnoDB (default) supports transactions and foreign keys. MyISAM is faster for read-heavy.