Adding a new column seems simple, but mistakes here can break queries, slow performance, or corrupt records. The right approach depends on your database, your schema design, and your production constraints.
In SQL, the basic syntax for most systems looks like:
ALTER TABLE table_name
ADD COLUMN column_name data_type;
In PostgreSQL, you can set defaults, constraints, and NOT NULL in the same statement. Be aware that adding a column with a default value and NOT NULL on a large table will rewrite the whole table. This can lock writes and cause downtime. If performance matters, add the column as nullable first, backfill data in batches, then set constraints.
In MySQL, be explicit about the position of the column only if required by legacy applications. Otherwise, let it append to the end. Many modern tools and ORMs ignore column order. Also note that some MySQL versions block the table during the schema change, so online schema change tools—like pt-online-schema-change—can be essential.