Open Source RDBMS - Seamless, Scalable, Stable and Free

한국어 | Login |Register

Versions available for this page: CUBRID 8.3.0 |  CUBRID 8.3.1 |  CUBRID 8.4.0 |  CUBRID 8.4.1 |  CUBRID 8.4.3 |  CUBRID 9.0.0 | 

ADD CONSTRAINT Clause

Description

You can add a new constraint by using the ADD CONSTRAINT clause.

By default, the index created when you add PRIMARY KEY constraints is created in ascending order, and you can define the key sorting order by specifying the ASC or DESC keyword next to the column name.

Syntax

ALTER [ TABLE | CLASS | VCLASS | VIEW ] table_name

ADD CONSTRAINT < constraint_name > column_constraint ( column_name_comma_list )

 

column_constraint::=

UNIQUE [ KEY ] |

PRIMARY KEY |

FOREIGN KEY [ <foreign_key_name> ] REFERENCES [referenced_table_name]( column_name_comma_list )

                       [ <referential_triggered_action> ... ]

 

<referential_triggered_action> ::=

{ ON UPDATE <referential_action> } |

{ ON DELETE <referential_action> } |

{ ON CACHE OBJECT cache_object_column_name }

 

<referential_action> ::=

CASCADE | RESTRICT | NO ACTION | SET NULL

  • table_name: Specifies the name of a table that has a constraint to be added.
  • constraint_name: Specifies the name of a constraint to be added, or it can be omitted. If omitted, a name is automatically assigned.
  • foreign_key_name: Specifies a name of the FOREIGN KEY constraint. You can skip the name specification. However, if you specify this value, constraint_name will be ignored, and the specified value will be used.
  • column_constraint: Defines a constraint for the specified column. For details, see Constraint Definition.
Example

ALTER TABLE a_tbl ADD CONSTRAINT PRIMARY KEY(id); 

ALTER TABLE a_tbl ADD CONSTRAINT PRIMARY KEY(id, no DESC);

ALTER TABLE a_tbl ADD CONSTRAINT UNIQUE u_key1(id);