uniquely identify a record. It is similar to unique constraint except that only one field of a table can be set as primary key. The primary key does not allow NULL values. Example showing Primary Key Constraint in the student table: CREATE TABLE Student ( Admno integer PRIMARY KEY, → Primary Key constraint Name char( ) NOT NULL, Gender char( ), Age integer, Place char( ), ); In the above example the Admno field has been set as primary key and therefore will help us to uniquely identify a record, it is also set NOT NULL , therefore this field value cannot be empty.
. . . DEFAULT Constraint The DEFAULT constraint is used to assign a default value for the field.
When no value is given for the specified field having DEFAULT constraint, automatically the default value will be assigned to the field. 12th Computer Chapter - - Structured Query Language Example showing DEFAULT Constraint in the student table: CREATE TABLE Student ( Admno integer PRIMARY KEY, Name char( )NOT NULL, Gender char( ), Age integer DEFAULT , → Default Constraint Place char( ) ); In the above example the “Age” field is assigned a default value of , therefore when no value is entered in age by the user, it automatically assigns to Age. . .
. Check Constraint This constraint helps to set a limit value placed for a field. When we define a check constraint on a single column, it allows only the restricted values on that field. Example showing check constraint in the student table: CREATE TABLE Student ( Admno integer PRIMARY KEY Name char( )NOT NULL, Gender char( ), Age integer CHECK (Age <= ), → Check Constraint Place char( ), ); In the above example the check constraint is set to Age field where the value of Age must be less than or equal to .
The check constraint may use relational and logical operators for condition. Note . . .
TABLE CONSTRAINT When the constraint is applied to a group of fields of the table, it is known as Table constraint. The table constraint is normally given at the end of the table