Sneha
Sneha
Order table:
O-id C-id Order date Shipping date
Relational database keys
Types:
1. Super key
2. Candidate key
3. Primary key
4. Alternate key
5. Unique key
6. Composite key
7. Foreign key
.
Super key:
It is a set of one or more attributes in a table that can be
uniquely identify a row in that table. In other words, a super key
can uniquely distinguish every tuple(row) in a relation(table)
A super key can consists of a single attribute or a combination of
attributes. However, it may contain unnecessary attributes
Candidate key:
The minimal super keys are called Candidate keys. It means a set
of one or more columns in a table that can be uniquely identify a
record, but it contains no unnecessary attributes
There can be multiple candidate keys in a table, but only one of
them is selected to be the primary key
.
Primary key:
It is the specific type of candidate key that is chosen to uniquely
identify each record in a table
It ensures that no duplicate or Null values exist for the primary
key column, making it the main unique identifier for records in
the table
Student Table:
Alternate key:
The candidate key other than primary key
Unique key:
It is a database constraint that ensures the values in a column(s)
are unique across all rows in the table
Unlike a primary key, a unique key can accept one null value, but
all other non-null values must be distinct
Composite key:
.
Foreign key:
Is a column or a set of columns in a database table that
establishes a link between the data in two tables.
The foreign key in one table refers to the primary key in another
table
This relation enforces the referential integrity
Customers
cust_id cust_name
1001 John
1002 Smith
Orders
Order-id Cust-id Order-date
1 1001 24-11-2024
2 1002 25-11-2024
DEALING WITH
CONSTRAINT VIOLATIONS
.
.r
Department Table:
DNo Dname Location
1 CSE Banglore
2 MECH Banglore
Entity Integrity constraint:
Key constraints:
• On inserting a value in the new tuple of a relation
which is already existing in another tuple of the
same relation, can cause violation of key constraints
• Employee Table:
Referential integrity:
• On inserting a value in the foreign key of relation 1,
for which there is no corresponding value in the
Primary key which is referred to in relation 2, in
such case Referential integrity is violated
.
Delete Operation:
To delete some of the existing relation on the
database
Referential integrity constraints:
• It causes violation only if the tuple in relation 1 is
deleted which is referenced by foreign key from
other tuples of table 2 in the database, if such
deletion t takes place then the values in the tuple of
the foreign key in table 2 will become empty, which
will eventually violate referential integrity constraint
Update Operation:
. To make changes in the value of some existing
tuples
.
THANK
YOU