Implementation of Integrity Constraints in Mysql
Implementation of Integrity Constraints in Mysql
constraints in MySql
Implementation of Primary Key:
CREATE TABLE students (
ID int NOT NULL,
LastName varchar(255) NOT NULL,
FirstName varchar(255) NOT NULL,
Age int
);
CREATE Composite Key
• What is composite key?
A composite key, in the context of relational
databases, is a combination of two or more
columns in a table that can be used to uniquely
identify each row in the table. Uniqueness is
only guaranteed when the columns are
combined; when taken individually the columns
do not guarantee uniqueness.
CREATE Composite Key
Implementation of UNIQUE
What is Unique key?
• A unique key is a set of one or more than one fields/columns of
a table that uniquely identify a record in a database table.
• It is little like primary key and it cannot have duplicate values.
• The unique key and primary key both provide a guarantee for
uniqueness for a column or a set of columns.
• There is an automatically defined unique key constraint within a
primary key constraint.
• There may be many unique key constraints for one table, but
only one PRIMARY KEY constraint for one table.
Unique Constraints
• Insert values into table teams :
Composite Unique key declaration
Foreign key
• A FOREIGN KEY is a field (or collection of
fields) in one table that refers to the PRIMARY
KEY in another table.
Declaration of foreign key constraints