Adding a new column is simple in theory and often complex in production. The schema change must be fast, safe, and clear. Performance matters. Data integrity matters more.
In SQL, creating a new column starts with ALTER TABLE. Example:
ALTER TABLE users ADD COLUMN last_login TIMESTAMP DEFAULT CURRENT_TIMESTAMP;
This command works well for small tables. On large datasets, it can lock writes and cause downtime. The right strategy depends on the database engine, table size, and the traffic pattern.
PostgreSQL can add a nullable column quickly because it stores the default in the metadata without rewriting every row. MySQL before 8.0 may still lock the table depending on the engine settings. Modern versions using ALGORITHM=INPLACE or INSTANT make the process faster.
When adding a new column with a default value, know your database’s execution plan. A full table rewrite is dangerous in high-load systems. Always test in a staging environment with realistic data volumes.