Unit2-Relational Database Model
Unit2-Relational Database Model
The relational database model in DBMS represents data in tables with rows
and columns, where each table is called a relation.
This model simplifies database management and ensures data accuracy by
organizing information into structured, inter-related tables.
It uses SQL to manage and query the data, and is widely used due to its
consistency and efficiency, especially for complex queries.
Core Concepts:
Relations (Tables):
Data is stored in tables, also known as relations. Each table represents an entity or a
relationship between entities.
Rows (Tuples):
Each row in a table represents a single instance or record of the entity.
Columns (Attributes):
Each column represents a specific characteristic or attribute of the entity.
Relationships:
Tables can be linked to each other through primary and foreign keys, establishing
relationships between different entities
.
Advantages:
Data Integrity:
The relational model enforces data integrity through constraints like primary keys and
foreign keys, ensuring data accuracy and consistency.
Data Independence:
The logical structure of the data (tables, views, etc.) is separate from the physical
storage, allowing changes to the physical storage without affecting how users access
the data.
SQL Support:
The standard query language, SQL, provides a consistent and efficient way to interact
with relational databases.
Flexibility and Scalability:
Relational databases are designed to handle a wide range of data sizes and can be
scaled to accommodate growing data needs.
Example:
The major purpose of the DBMS is to provide users with an abstract view of the data,
which hides the details of how the system stores and maintains the data.
Data Abstraction
Physical level
This describes where the data physically resides and the specifics of how the
data is stored.
Logical level
This the schema of the database, describes the data and its relationships
View level
This level describes the data that is presented to the user and can present only a
portion of a database, or can be a composite from more than one database.
Abstraction:
It hides the complexities of how data is physically stored (e.g., file structures, indexing
methods) from users and applications.
Data independence:
Changes to the physical storage of data (e.g., moving data to a different server,
adding a new index) should not affect the logical view or require changes to
applications that use it.
Conceptual representation:
It defines the data elements, their attributes, and the relationships between them.
User-specific:
Logical views can be tailored to the specific needs of different users or applications,
providing them with a customized view of the data.
Example:
Imagine a database with employee information. A logical view might present
the data as a table with columns like "Employee ID", "Name", "Department",
and "Salary". The user of this view doesn't need to know how the data is
physically stored (e.g., whether it's in a single table or split across multiple
tables, how the data is indexed).
Keys
A key is an attribute or set of attributes that help to uniquely identify a record or a row of
data in a table(relation).
Why do we need Keys?
1. Keys are used to establish and identify relationships between tables/relations.
2. They uniquely identify any record/row inside a table/relation.
3. They also ensure that data integrity is maintained.
Types keys in DBMS/RDBMS
The different types of keys in DBMS/RDBMS are:
Super Key
Candidate Key
Primary Key
Alternate Key
Foreign Key
For understanding the different types of keys better, let us consider the below table. In
this ‘Student’ table, ID, Registration_No. and Name of students are given.
Super Key
If a set of one or more attributes can uniquely identify the entities of an entity set, then it
is called a super key.
NOTE: {Name} is not a super key as there is more than one record/row with the same
name.
Candidate Key
Candidate keys are selected from a set of super keys. If a super key has no
unnecessary attributes, then such a minimal super key is called a candidate key. It is
also termed as ‘Minimal Super Key’.
Primary Key
Primary keys are selected from a set of candidate keys. It is a candidate key selected
by the database designer to uniquely identify the records of a table.
The primary key field of a table must be unique and cannot be null.
A table does not contain more than one primary key.
Alternate Key
If a candidate key is not selected as a primary key then it is called an alternate key.
Foreign Key
If two relations or tables have a common attribute, which is the primary key in one table
and a non-key attribute in another table, then such a non-key attribute is called a foreign
key.
A table can contain zero or more foreign keys.
It helps to combine the tuples of two tables during the join operation.