ALTER COLUMN is a clause of the ALTER TABLE statement that lets you change the attributes of an existing column without dropping and recreating the table. Typical actions include changing the data type, adjusting length or precision, setting or dropping NOT NULL and DEFAULT constraints, renaming the column, or changing collation. Most relational databases support ALTER COLUMN, but exact capabilities and required clauses vary. Some engines (e.g., PostgreSQL) require USING expressions when converting incompatible types, while others (e.g., MySQL) expect the full column definition to be restated. ALTER COLUMN is transactional in databases that support DDL transactions (PostgreSQL, SQL Server), meaning changes can be rolled back. Be mindful that altering large tables can lock the table and may rewrite data, potentially causing long-running operations.
table_name
(identifier) - Name of the table containing the column.column_name
(identifier) - The column to be modified.new_data_type
(data type) - Target data type or new size/precision.expression
(expression) - Expression to cast existing data (dialect-specific).ALTER TABLE, ADD COLUMN, DROP COLUMN, RENAME COLUMN, SET DEFAULT, NOT NULL constraint
SQL-92 standard (ALTER TABLE enhancements)
No. Renaming uses `ALTER TABLE table_name RENAME COLUMN old_name TO new_name;`.
Yes. In MySQL you must use `MODIFY column_name new_definition` and include type, nullability, and default.
Use `ALTER TABLE table_name ALTER COLUMN column_name DROP NOT NULL;` (PostgreSQL) or `MODIFY column_name datatype NULL` (MySQL).
The database rejects the ALTER operation, raising an error unless you first clean or convert the data.