Creating a new column in a database is simple in theory, but precision matters. A single mistake can break queries, corrupt data, or cause downtime. Whether you use PostgreSQL, MySQL, or SQLite, the process follows the same principle: define the column, set its type, and choose defaults that won’t disrupt existing rows.
In SQL, ALTER TABLE is the command that matters. For example:
ALTER TABLE users
ADD COLUMN last_login TIMESTAMP DEFAULT NOW();
This creates the new column without touching current data, while setting a usable default for future inserts. For large tables, add the column in a way that avoids full table rewrites. In PostgreSQL, adding a nullable column with a default defined after creation is faster: