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

Database Systems - Lecture 6

Uploaded by

Meregulwa Allan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
21 views

Database Systems - Lecture 6

Uploaded by

Meregulwa Allan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

RELATIONAL DATABASES

CONCEPTUAL SCHEMA AND RELATIONAL SCHEMA

CONCEPTUAL SCHEMA
A conceptual schema defines an abstract view of the data and the relationships among data
entities.
This schema is independent of any specific DBMS.

Characteristics of Conceptual Schema

• Focuses on high-level entities, attributes, and relationships.


• Uses entity-relationship diagrams (ERD) or UML class diagrams to model data.
• Abstracts the logical aspects of data organization, hiding the details of how data will be
stored or retrieved.

Use Cases of Conceptual Schema

• Database design: It helps in understanding the domain and modeling the data requirements
without worrying about implementation.
• Communication: Acts as a bridge between the database designers and business users to
ensure the correct interpretation of the data.
• Documentation: Provides a complete and structured view of the organization’s data.

RELATIONAL SCHEMA

A relational schema defines how data is organized in tables, specifying the relations, columns,
and keys.

Characteristics of Relational Schema

• Describes tables, columns, data types, primary and foreign keys, and constraints.
• More focused on the logical data model as it will be implemented in a database.
• Normalization techniques are applied to avoid redundancy and maintain integrity.

Use Cases of Relational Schema


• Database implementation: Used to create tables and define relationships within an
RDBMS like MySQL, PostgreSQL, etc.
• Query formulation: Helps in writing SQL queries by understanding the structure of the
tables and their relations.

1
CONCEPTUAL SCHEMA VS RELATIONAL SCHEMA

MAPPING CONCEPTUAL SCHEMA TO RELATIONAL SCHEMA


• Mapping between these schemas ensures that the abstract design of a system is correctly
implemented in a relational database.
• To translate a conceptual schema (ERD) into a relational schema, the entities and
relationships are converted into tables and constraints.
The process typically follows the following steps:
1. Entities to Tables:
 Each entity in the conceptual schema is mapped to a table in the relational schema
 The attributes of the entity become the columns of the table
 The primary key is identified based on the unique identifier of the entity
Example:
If the conceptual schema has an entity Student, it is mapped to a table Student with attributes
like StudentID, Name and DOB.
2. Relationships to Foreign Keys:
 Relationships between entities (e.g., one-to-one, one-to-many, many-to-many) are
mapped by introducing foreign keys in the related tables.
 For a one-to-one or one-to-many relationship, a foreign key is added to the table on the
"many" side.
 For a many-to-many relationship, a new junction table is introduced to hold the foreign
keys of both participating entities.

2
Example:
A one-to-many relationship between Student and Course (where a student can enroll in
multiple courses) is mapped by adding StudentID as a foreign key in the Enrollment table.
3. Attributes to Columns:
• The non-key attributes of the entities are directly mapped to columns in the corresponding
tables
• Data types are specified for each attribute based on the requirements (e.g., string, integer,
date).
4. Handling Composite and Multi-Valued Attributes:
• Composite attributes (attributes that can be subdivided) are flattened into multiple
columns.
• Multi-valued attributes (attributes that can have multiple values) are often transformed
into separate tables with a foreign key relationship.
5. Normalization:
• The relational schema is normalized to reduce redundancy and ensure data integrity.
• Tables are checked for various normal forms (1NF, 2NF, 3NF, etc.) and reorganized
accordingly.

EXAMPLE OF MAPPING:

Conceptual Schema
• Entity: Employee with attributes EmployeeID, Name, DOB
• Relationship: WorksIn between Employee and Department (one-to-many)

Relational Schema:
• Table: Employee(EmployeeID, Name, DOB, DepartmentID
• Table: Department(DepartmentID, DeptName)
• Foreign Key: DepartmentID in employee references Department(DepartmentID)

ENTITY INTEGRITY CONSTRAINT


The Entity Integrity Constraint ensures that every table in a relational database has a primary
key and that the value of the primary key is unique and never null.
This guarantees that each record (row) in the table can be uniquely identified.

3
Uses of Entity Constraint
• Uniqueness of Records: Ensures that each record in a table is distinct, preventing
duplication of data.
• Efficient Data Retrieval: Primary keys facilitate fast and efficient searching, sorting, and
querying of data in a table.
• Data Integrity: Helps maintain data integrity by ensuring that no record is ambiguous or
can be confused with another.

Example:

In a table Employee, the EmployeeID column is the primary key. The entity integrity constraint
ensures that every employee has a unique EmployeeID and no employee can have a null value
for EmployeeID

REFERENTIAL INTEGRITY CONSTRAINT


The Referential Integrity Constraint ensures the validity of relationships between tables by
enforcing foreign key values to match valid primary key values in related tables, maintaining
data consistency across the database.
NOTE:
Foreign Key: A column or set of columns in one table that refers to the primary key in another
table.
Consistency: If a foreign key is set, it must refer to an existing, valid primary key in the related
table.
Cascading Actions: Referential integrity can be enforced with actions like ON DELETE
CASCADE or ON UPDATE CASCADE to maintain consistency when the referenced record
is updated or deleted.

4
Uses of Referential Integrity Constraint
• Enforcing Relationships Between Tables: Ensures that records in one table are validly
related to records in another. For instance, an order must always be associated with an
existing customer.
• Maintaining Consistency: Prevents orphaned records or invalid references in a database,
ensuring the relationships between tables are always valid.
• Cascading Changes: When a referenced record is deleted or updated, the referential
integrity constraint can automatically update or delete related records.

Example:
In a database with Orders and Customer tables, the CustomerID in the Orders table is a foreign
key referencing the CustomerID in the Customer table. Referential integrity ensures that every
order has a valid CustomerID.

In the above example, the CustomerID in the Orders table must correspond to an existing
CustomerID in the Customer table.
If an attempt is made to insert an order with a non-existent CustomerID, the database will reject
the action.

ENTITY INTEGRITY VS REFERENTIAL INTEGRITY

5
6

You might also like