University of Information Technology & Sciences: Course Name:-Database Management System Lab
University of Information Technology & Sciences: Course Name:-Database Management System Lab
Sciences
Assignment 02
Submitted by:-
Shakilur Rahman
ID:-1814351038
Section:- B
Dept. Of CSE
Types of constraint
• NOT NULL
• UNIQUE
• DEFAULT
• CHECK
• Key Constraints – PRIMARY KEY, FOREIGN KEY
• Domain constraints
• Mapping constraints
NOT NULL:
NOT NULL constraint makes sure that a column does not hold NULL value.
When we don’t provide value for a particular column while inserting a record into
a table, it takes NULL value by default. By specifying NULL constraint, we can be
sure that a particular column(s) cannot have NULL values.
Example:
UNIQUE:
UNIQUE Constraint enforces a column or set of columns to have unique values.
If a column has a unique constraint, it means that particular column cannot have
duplicate values in a table.
DEFAULT:
The DEFAULT constraint provides a default value to a column when there is no
value provided while inserting a record into a table.
CHECK:
This constraint is used for specifying range of values for a particular column of a
table. When this constraint is being set on a column, it ensures that the specified
column must have the value falling in the specified range.
Key constraints:
PRIMARY KEY:
Primary key uniquely identifies each record in a table. It must have unique values
and cannot contain nulls. In the below example the ROLL_NO field is marked as
primary key, that means the ROLL_NO field cannot have duplicate and null
values.
Domain constraints:
Each table has certain set of columns and each column allows a same type of
data, based on its data type. The column does not accept values of any other
data type.
Domain constraints are user defined data type and we can define them like this:
Mapping constraints:
Mapping Cardinality:
One to One: An entity of entity-set A can be associated with at most one entity of
entity-set B and an entity in entity-set B can be associated with at most one entity
of entity-set A.
Example: