0% found this document useful (0 votes)
32 views

Implementation of Integrity Constraints in Mysql

1) The document discusses various integrity constraints in MySQL including primary keys, default constraints, NOT NULL constraints, composite keys, unique keys, and foreign keys. 2) It provides examples of declaring primary keys, default constraints, NOT NULL constraints, and creating composite keys in MySQL. 3) A composite key is defined as a combination of two or more columns in a table that can uniquely identify each row when combined, even if the columns are not unique individually.

Uploaded by

Babe Sultana
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
32 views

Implementation of Integrity Constraints in Mysql

1) The document discusses various integrity constraints in MySQL including primary keys, default constraints, NOT NULL constraints, composite keys, unique keys, and foreign keys. 2) It provides examples of declaring primary keys, default constraints, NOT NULL constraints, and creating composite keys in MySQL. 3) A composite key is defined as a combination of two or more columns in a table that can uniquely identify each row when combined, even if the columns are not unique individually.

Uploaded by

Babe Sultana
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 18

Implementation of Integrity

constraints in MySql
Implementation of Primary Key:

• Declaration of PRIMARY KEY :


Alternate Declaration of PRIMARY KEY
CREATE Primary Key for TEXT data type
DEFAULT Constraint

• Used to provide a default value for a column.


• The default value will be added to all new
records if no other value is specified.
• CREATE TABLE student (
    ID int NOT NULL,
    LastName varchar(255),
    FirstName varchar(255),
    Age int,
    City varchar(255) DEFAULT ’Dhaka'
);
NOT NULL Constraint

• By default, a column can hold NULL values.


• NOT NULL constraint enforces a column to
NOT accept NULL values.
NOT NULL Constraint

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

You might also like