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

Relational Database

Uploaded by

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

Relational Database

Uploaded by

Imrooz Ali Shah
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 26

R E L AT I O N A L

D ATA B A S E
R E L AT I O N A L D ATA B A S E M O D E L

The relational model used the basic concept of a relation or table

Relational data model is the primary data model, which is used widely
around the world for data storage and processing

This model is simple and it has all the properties and capabilities required
to process data with storage efficiency
R E L AT I O N A L M O D E L C O N C E P T S
Tables − In the relational data model, relations are saved in the format of Tables. A table has rows and
columns, where rows represent records and columns represent the attributes.

Tuple − A single row of a table, which contains a single record for that relation is called a tuple

Attribute / Field – Each column represents attribute or field

Relation Key − Each row has one or more attributes, known as relation key, which can identify the row in
the relation uniquely

Attribute domain − Every attribute has some predefined value scope, known as attribute domain
R E L AT I O N A L D ATA B A S E
KEY CONSTRAINTS

CONSTRAINTS
OF
DOMAIN CONSTRAINTS
R E L AT I O N A L
D ATA B A S E

REFERENTIAL
INTEGRITY
CONSTRAINTS
KEY CONSTRAINTS
There must be at least one minimal subset of attributes in the relation,
which can identify a tuple uniquely. This minimal subset of attributes is
called key for that relation. If there are more than one such minimal
subsets, these are called candidate keys.
In a relation with a key attribute, no two tuples can have identical values
for key attributes

A key attribute cannot have NULL values


DOMAIN
CONSTRAINTS
Attributes have specific values in real-world scenarios, for example, age can only
be a positive integer.

The same constraints have been tried to employ on the attributes of a relation

Every attribute is bound to have a specific range of values. For example, age


cannot be less than zero and telephone numbers cannot contain a digit outside 0-9.
REFERENTIAL
INTEGRITY
CONSTRAINTS
• Referential integrity constraints work on the
concept of Foreign Keys
• A foreign key is a key attribute of a relation that
can be referred in other relation
• Referential integrity constraint states that if a
relation refers to a key attribute of a different or
same relation, then that key element must exist
FUNCTIONS OF
R E L AT I O N A L
MODEL
• Relational model performs "select",
"project" and "join" database operations.
• Where select is used for data retrieval
• Project identifies data attributes.
• Join combines relations
F U N C T I O N S O F   R E L AT I O N A L M O D E L
A D VA N T A G E S O F R E L A T I O N A L
MODEL
Easy extendibility, as new data may be added without modifying existing
records. This called scalability

New technology performance, power and flexibility with multiple data


requirement capabilities

Data security, which is critical when data sharing is based on privacy


R E L AT I O N S H I P
• A relationship in the context of database, is a
situation that exists between two relational
database tables when one table has a foreign key
that references the primary key of the other table
• Relationships allow relational database to split
and store data in different tables, while linking
dissimilar data items
FOR EXAMPLE
• In a bank database a CUSTOMER_MASTER table stores customer
data with a primary key column
• It also stores customer data in an ACCOUNTS_MASTER table,
which holds information about various bank accounts and associated
customers
• To link these two tables and determine customer and bank account
information, a corresponding CUSTOMER_ID column must be
inserted in the ACCOUNTS_MASTER table, referencing existing
customer IDs from the CUSTOMER_MASTER table
• In such case, the ACCOUNTS_MASTER table’s CUSTOMER_ID
column is a foreign key that references a column with the same name
in the CUSTOMER_MASTER table
T Y P E S O F R E L AT I O N S H I P S

ONE-TO-MANY MANY-TO-MANY ONE-TO-ONE


RELATIONSHIP RELATIONSHIPS RELATIONSHIPS
T Y P E S O F R E L AT I O N S H I P S
 The degree of relationship also known as cardinality, is the number of occurrences in one entity
which are associated (or linked) to the number of occurrences in another. 

 1)    One-to-Many Relationship (1 : M)

 2)    Many-to-Many Relationships (M : M) 

3)    One-to-One Relationships (1 : 1)


TYPES OF
R E L AT I O N S H I P
R E L AT I O N A L  K E Y S
IN RDBMS

• Super Key
• Candidate Key
• Primary Key
• Composite Key
• Secondary or Alternate Key
• Foreign Key

• Non-Key Attribute
SUPER KEY
• Super Key is defined as a set of attributes within a table
that uniquely identifies each record within a table.
• Candidate keys are selected from the set of super keys, the
only thing we take care while selecting candidate key is: It
should not have any redundant attribute.

Employee_CNIC Employee_ID Employee_Name


SUPER KEY

A certain set of columns may be extracted and guaranteed unique to each


customer. Examples of super keys are as follows:

Name + CNIC ID + Name +


+ Birthdate CNIC
C A N D I D AT E K E Y
Candidate keys are defined as the set of fields
from which primary key can BE selected.

It is an attribute or set of ATTRIBUTES that can


act as a PRIMARY key for a table to uniquely
identify each record in that table.
E X A M P L E O F A C A N D I D AT E K E Y

Candidate Key ↓
Student_ID​ Student_Cellphone​ Age​ Course​ Address​
​ ​ ​ ​ ​
PRIMARY KEY

Primary key is a candidate key that is most


appropriate to become main key of the table. It is a
key that uniquely identify each record in a table.

Primary Key ↓
Student_ID Student_Name Age Course Address
COMPOSITE KEY
Key that consist of two or more attributes that uniquely identify an entity
occurrence is called Composite key.
But any attribute that makes up the Composite key is not a simple key in its
own.
Composite Key ↓
Customer_ID Order_ID Sales_Detail
S E C O N D A R Y O R A LT E R N AT I V E K E Y
Out of all candidate keys, only one gets selected as primary key, remaining keys are known as
alternate or secondary keys.

                                Alternate
Key ↓
Student_ID Student_Cellphone Age Course Address

Primary Key ↑
FOREIGN KEY
• Foreign keys are the columns of a table that points to the primary
key of another table.
• They act as a cross-reference between tables.

                                Foreign Key ↓
Srudent_ID Course_ID
N O N - K E Y AT T R I B U T E
Non-key attributes are attributes other than candidate key
attributes in a table.

Non-Key Attribute ↓
Student_ID Student_Name Age Course Address

You might also like