Adding a new column should be precise, fast, and predictable. In SQL, it starts with an ALTER TABLE command. Choose the right data type. Define constraints. Default values matter—set them correctly or you will regret it later. Every choice you make affects query speed, data integrity, and migration safety.
In PostgreSQL, the syntax is direct:
ALTER TABLE users ADD COLUMN last_login TIMESTAMP DEFAULT NOW();
This change runs instantly for empty tables but in production it can lock writes. Plan for downtime or use concurrent methods. For MySQL, watch out for storage engine behavior. For SQLite, remember migrations rewrite the file—keep backups.
Schema migrations often happen with ORM tools like Prisma, Sequelize, or ActiveRecord. They generate migration files that run ALTER TABLE under the hood. Always review generated SQL before running it on live data. Test in staging with production-sized datasets. Measure the performance impact.