Single-Column Constraint Format

Use the Single-Column Constraint format to define and declare the name of at least one constraint on a single column, and to specify the mode of each constraint.

The Single-Column Constraint format can associate one or more constraints with a column, in order to perform any of the following tasks:
  • Create one or more data-integrity constraints for a column.
  • Specify a meaningful name for a constraint.
  • Specify the constraint-mode that controls the behavior of a constraint during insert, delete, and update operations.

This syntax fragment is part of the Column definition.

Read syntax diagramSkip visual syntax diagram
Single-Column Constraint Format

     .-+-+-NULL-----+------------------+--+-------------------------------------+-.     
     | | '-NOT NULL-'                  |  |  (1)                            (4) | |     
     | |    (1)                        |  '-------| Constraint Definition |-----' |     
     | +-+-------DISTINCT-+------------+                                          |     
     | | +-UNIQUE---------+            |                                          |     
     | | '-PRIMARY KEY----'            |                                          |     
     | |                         (2)   |                                          |     
     | '-+-| REFERENCES Clause |-----+-'                                          |     
   .-|   |                  (3)      |                                            |-.   
   V |   '-| CHECK Clause |----------'                                            | |   
|----+----------------------------------------------------------------------------+-+--|

Notes:
  1. Informix® extension
  2. See REFERENCES Clause
  3. See CHECK Clause
  4. See Constraint Definition

The NULL constraint specifies that the column can store NULL values. It is not valid for columns of serial or complex data types. The CREATE TABLE statement fails with an error if you specify both NOT NULL and NULL constraints on the same column.

The following example creates a standard table with two constraints: num, a primary-key constraint on the acc_num column; and code, a unique constraint on the acc_code column:
CREATE TABLE accounts (
   acc_num   INTEGER PRIMARY KEY CONSTRAINT num,
   acc_code  INTEGER UNIQUE CONSTRAINT code,
   acc_descr CHAR(30));

The types of constraints used in this example are defined in sections that follow.


Copyright© 2019 HCL Technologies Limited