Opens your running SynapCores (Default Values will be staged for a preview — nothing runs until you click Run). No instance yet? Install free in ~30s.
Share
Objective
Create tables with DEFAULT values that automatically populate columns when no value is provided during INSERT. Defaults simplify data entry and ensure consistent initial values.
Step 1: Basic Default Values
Create a table with various default values.
CREATE TABLE user_profiles (
id INTEGER PRIMARY KEY,
username VARCHAR(50) NOT NULL,
email VARCHAR(255),
status VARCHAR(20) DEFAULT 'active',
role VARCHAR(30) DEFAULT 'member',
login_count INTEGER DEFAULT 0,
is_verified BOOLEAN DEFAULT FALSE,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
Step 2: Insert Without Specifying Defaults
Insert records without specifying columns that have defaults.
-- Only specify required columns - defaults fill the rest
INSERT INTO user_profiles (id, username, email) VALUES
(1, 'alice', 'alice@example.com'),
(2, 'bob', 'bob@example.com'),
(3, 'charlie', 'charlie@example.com');
Step 3: Verify Default Values Applied
Check that default values were automatically applied.
SELECT
username,
status,
role,
login_count,
is_verified,
created_at
FROM user_profiles;