Adding a new column to a database table is simple in syntax but significant in impact. Whether in PostgreSQL, MySQL, or SQLite, the operation changes schema, affects queries, and can alter performance. Precision matters. In SQL, the basic form is:
ALTER TABLE table_name
ADD COLUMN column_name data_type;
This creates the new column with the specified type. In most engines, it will be appended to the table definition but not filled with values unless you set a default. Defaults can be static values or expressions, but be mindful—on large tables, adding a column with a default can lock writes or trigger a full table rewrite.
For PostgreSQL, adding a nullable column is fast. Adding one with a non-null default in older versions rewrites the table; in newer versions, defaults are stored in metadata and applied on read until updated. MySQL often locks the table during ALTER TABLE, though InnoDB and newer versions offer some online DDL capabilities. Always check the engine documentation for specifics before running an operation on production.