DEFAULT with Function
DEFAULT with Function is a SQL statement in the Constraints category. DEFAULT values can be function calls that generate dynamic values like timestamps or UUIDs. The syntax is column type DEFAULT function_name(). It returns dynamic default value. A typical example: CREATE TABLE audit_log ( id INT PRIMARY KEY AUTO_INCREMENT, action VARCHAR(50), created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, created_by VARCHAR(100) DEFAULT CURRENT_USER, session_id UUID DEFAULT gen_random_uuid() -- PostgreSQL ); INSERT INTO audit_log (action) VALUES ('LOGIN'); -- created_at = NOW(), created_by = current_user, session_id = random UUID -- MySQL: DEFAULT CURRENT_TIMESTAMP -- PostgreSQL: DEFAULT NOW(), DEFAULT gen_random_uuid() -- SQL Server: DEFAULT GETDATE(), DEFAULT NEWID() A close relative is PRIMARY KEY, which a column or set of columns that uniquely identifies each row. Only one PK per table. Automatically creates a unique index. A close relative is FOREIGN KEY, which ensures referential integrity: values in this column must exist in the referenced parent table.