ALTER TABLE

Synopsis

Use the ALTER TABLE statement to change the definition of an existing table.

Syntax

  1. alter_table ::= ALTER TABLE [ ONLY ] name [ * ] alter_table_action
  2. [ , ... ]
  3. alter_table_action ::= ADD [ COLUMN ] column_name data_type
  4. | RENAME TO table_name
  5. | DROP [ COLUMN ] column_name
  6. [ RESTRICT | CASCADE ]
  7. | ADD alter_table_constraint
  8. | DROP CONSTRAINT constraint_name
  9. [ RESTRICT | CASCADE ]
  10. | RENAME [ COLUMN ] column_name TO column_name
  11. | DISABLE ROW LEVEL SECURITY
  12. | ENABLE ROW LEVEL SECURITY
  13. | FORCE ROW LEVEL SECURITY
  14. | NO FORCE ROW LEVEL SECURITY
  15. alter_table_constraint ::= [ CONSTRAINT constraint_name ]
  16. { CHECK ( expression )
  17. | UNIQUE ( column_names )
  18. index_parameters
  19. | FOREIGN KEY ( column_names )
  20. references_clause }

alter_table

ALTER TABLE - 图1

alter_table_action

ALTER TABLE - 图2

alter_table_constraint

ALTER TABLE - 图3

Semantics

alter_table

ALTER TABLE [ ONLY ] name [ * ] alter_table_action [ , … ]

Alter the specified table and dependencies.

  • ONLY — Limit the change to the specified table.

alter_table_action

Specify one of the following actions.

ADD [ COLUMN ] column_name data_type

Add the specified column with the specified data type.

RENAME TO table_name

Rename the table to the specified table name.

DROP [ COLUMN ] column_name [ RESTRICT | CASCADE ]

Drop the named column from the table.

  • RESTRICT — Remove only the specified

ADD alter_table_constraint

Add the specified constraint to the table. For descriptions of valid table_constraint values, see CREATE TABLE.

DROP CONSTRAINT constraint_name [ RESTRICT | CASCADE ]

Drop the named constraint from the table.

  • RESTRICT — Remove only the specified constraint.
  • CASCADE — Remove the specified constraint and any dependencies.

RENAME [ COLUMN ] column_name TO column_name

Rename a column to the specified name.

ENABLE / DISABLE ROW LEVEL SECURITY

This enables or disables row level security for the table.If enabled and no policies exist for the table, then a default-deny policy is applied.If disabled, then existing policies for the table will not be applied and will be ignored.See CREATE POLICY for details on how to create row level security policies.

FORCE / NO FORCE ROW LEVEL SECURITY

This controls the application of row security policies for the table when the user is the table owner.If enabled, row level security policies will be applied when the user is the table owner.If disabled (the default) then row level security will not be applied when the user is the table owner.See CREATE POLICY for details on how to create row level security policies.

alter_table_constraint

Specify a table constraint.

CONSTRAINT constraint_name

Specify the name of the constraint.

CHECK ( expression ) | FOREIGN KEY ( column_names ) reference_clause

See also