Adding a new column sounds simple. In reality, it touches schema design, data integrity, query performance, and deployment safety. Whether you use PostgreSQL, MySQL, or a distributed database, making the change without breaking production takes planning.
First, define the purpose of the new column. Decide on the data type. Use the smallest type that fits the data to reduce memory and storage overhead. Avoid nullable columns where possible; defaults help maintain consistency and speed queries.
Next, apply the addition in a controlled way. In SQL, the syntax is direct:
ALTER TABLE users ADD COLUMN last_login TIMESTAMP NOT NULL DEFAULT NOW();
But production requires more than syntax. On large tables, ALTER TABLE may lock writes. Consider online schema migration tools like pt-online-schema-change or gh-ost to avoid downtime. For high-traffic systems, deploy the new column in phases — schema change first, then code updates that write to it, then code that reads from it.