Adding a new column in SQL changes the table schema. In PostgreSQL, use:
ALTER TABLE users ADD COLUMN last_login TIMESTAMP;
In MySQL:
ALTER TABLE users ADD COLUMN last_login DATETIME;
A new column impacts indexes, queries, and the application layer. Large tables make schema changes costly. Without care, a simple ALTER TABLE can lock writes and block reads. On production systems, run the migration during low traffic or use tools like pt-online-schema-change for MySQL or pg_repack for PostgreSQL.
When adding nullable columns, the database only updates metadata—fast and safe. Adding a column with a default value in older PostgreSQL versions rewrites the entire table, which can be slow. Newer versions (11+) store the default in metadata, avoiding a rewrite.