A missing column in production halted every API call. Logs filled with errors. Deploys paused. Customers waited. The only fix was clear: add a new column fast, without breaking the rest of the database.
Creating a new column is a common task in modern development. It is also one of the most dangerous when done under pressure. The wrong migration can lock tables for minutes or hours. It can cascade failures. The best engineers prepare for this action before it becomes an emergency.
To add a new column in SQL, start by defining the column name, type, and constraints. Use migrations to keep schema changes versioned and predictable. Example for PostgreSQL:
ALTER TABLE users
ADD COLUMN last_login TIMESTAMPTZ DEFAULT NOW();
In large tables, use non-blocking methods. For PostgreSQL, tools like pg_safe_alter or background migrations prevent downtime. In MySQL, pt-online-schema-change is a safe option. Always test queries on a staging environment before running them in production.