Creating a new column in SQL follows a simple pattern, but precision matters. The command is straightforward:
ALTER TABLE users ADD COLUMN last_login TIMESTAMP;
This adds a column named last_login to the users table, storing date and time values. Use explicit data types. Avoid NULL defaults unless you have a clear reason. Every new column should align with current and future query patterns.
In PostgreSQL, adding a new column with a default value updates every row, which can lock the table. For high-volume datasets, first add the column without the default, then update in batches, and finally set the default in schema.
In MySQL, adding columns can trigger a full table rewrite depending on the storage engine. Review your version and engine settings before running migrations in production. Test changes in a staging environment with realistic data size.