Skip to content

Latest commit

 

History

History
62 lines (40 loc) · 2.28 KB

alter-column.md

File metadata and controls

62 lines (40 loc) · 2.28 KB
title summary toc
ALTER COLUMN
Use the ALTER COLUMN statement to change a column's Default constraint.
false

The ALTER COLUMN statement is part of ALTER TABLE and changes a column's Default constraint or drops the Not Null constraint.

{{site.data.alerts.callout_info}}To manage other constraints, see ADD CONSTRAINT and DROP CONSTRAINT{{site.data.alerts.end}}

Synopsis

{% include sql/diagrams/alter_column.html %}

Required Privileges

The user must have the CREATE privilege on the table.

Parameters

Parameter Description
table_name The name of the table with the column whose Default Value you want to modify.
name The name of the column you want to modify.
a_expr The new Default Value you want to use.

Examples

Set or Change a Default Value

Setting the Default Value constraint inserts the value when data's written to the table without explicitly defining the value for the column. If the column already has a Default Value set, you can use this statement to change it.

The below example inserts the Boolean value true whenever you inserted data to the subscriptions table without defining a value for the newsletter column.

> ALTER TABLE subscriptions ALTER COLUMN newsletter SET DEFAULT true;

Remove Default Constraint

If the column has a defined Default Value, you can remove the constraint, which means the column will no longer insert a value by default if one is not explicitly defined for the column.

> ALTER TABLE subscriptions ALTER COLUMN newsletter DROP DEFAULT;

Remove Not Null Constraint

If the column has the Not Null constraint applied to it, you can remove the constraint, which means the column becomes optional and can have NULL values written into it.

> ALTER TABLE subscriptions ALTER COLUMN newsletter DROP NOT NULL;

See Also