Five constraints of the database and adding methods

Five constraints

1.  Primary key constraint primay key Constraint : uniqueness and non-emptiness

2.  The only constraint of Unique Constraint : uniqueness may be empty but only one

3.  Check constraints Check Constraint: limit the scope of the series of data format

4.  Default constraint Default OCnstraint : the default value of the data

5.  Foreign key constraint Foreign keyConstraint: Need to establish a relationship between the two tables and reference the columns of the main table

Syntax example of the five constraints:

1. Add primary key constraints

Alter table table name add Constraint primary key name primary key ( field )

2.   Add unique constraints

Alter table table name add Constraint constraint name unique ( field )

3.   Add default constraints

Alter table table name add Constraint constraint name default (default content) for field name

4.   Add check constraints

Alter table table name add Constraint constraint name check ( field expression )

5.   Add foreign key constraints

    Alter table table name add COnstraint constraint name foreign key ( field ) references table name (field name) 

Guess you like

Origin blog.csdn.net/ke_new/article/details/78547479