Unit 4 Database System (1)
Unit 4 Database System (1)
• The relational model is a way of organizing data into tables for efficient
management, retrieval, and analysis. It's used in database management
systems (DBMS).
How it works
•Data is represented in tables, with rows representing records and columns
representing attributes
•The logical data structures are separate from the physical storage structures.
This separation allows database administrators to manage physical storage
without affecting access to the data .
•It is easier to manage, retrieve, and analyze data.
Advantages of Relational Database Model
• It is simpler than the hierarchical model and network model.
• It is easy and simple to understand.
• Its structure can be changed anytime upon requirement.
•Data Integrity: The relational database model enforces data integrity through various constraints such as
primary keys and foreign keys. This ensures that the data in the database is accurate, consistent, and valid.
•Flexibility: The relational database model is highly flexible and can handle a wide range of data types and
structures. It also allows for easy modification and updating of the data without affecting other parts of the
database.
•Scalability: The relational database model can scale to handle large amounts of data by adding more tables, indexe
or partitions to the database. This allows for better performance and faster query response times.
•Security: The relational database model provides robust security features to protect the data in the database.
These include user authentication(confirmation) and authorization(agreement) of sensitive data.
•Data consistency: The relational database model ensures that the data in the database is consistent across
all tables. This means that if a change is made to one table, the corresponding changes will be made to all related
tables.
•Query Optimization: The relational database model provides a query(demand) optimizer that can analyze and
Disadvantages of the Relational Model
• Few database relations have certain limits which can’t be expanded further.
• It can be complex and it becomes hard to use.
• Complexity: The relational model can be complex and difficult to understand, particularly for
users who are not familiar with SQL and database design principles. This can make it
challenging to set up and maintain a relational database.
• Performance: The relational model can suffer from performance issues when dealing with
large data sets or complex queries. In particular, joins between tables can be slow, and
indexing strategies can be difficult to optimize.
• Scalability: While the relational model is generally scalable, it can become difficult to
manage as the database grows in size. Adding new tables or indexes can be time-consuming,
and managing relationships between tables can become complex.
• Cost: Relational databases can be expensive to license and maintain, particularly for large-
scale deployments. Additionally, relational databases often require dedicated hardware and
specialized software to run, which can add to the cost.
• Data redundancy: In some cases, the relational model can lead to data redundancy, where the
same data is stored in multiple tables. This can lead to inefficiencies and can make it difficult
to ensure data consistency across the database
4.2. Relational Model Constraints and Relational Database Schemas
•Explanation: In the above relation, Name is a composite attribute and Phone is a multi-
values attribute, so it is violating domain constraint.
2. Key Constraints
These are called uniqueness constraints since it ensures that every tuple in the relation
should be unique. An attribute that can uniquely identify a tuple in a relation is called the
key of the table.
• A relation can have multiple keys or candidate keys(minimal super key), out of which
we choose one of the keys as the primary key, we don’t have any restriction on choosing
the primary key out of candidate keys.
• Null values are not allowed in the primary key, hence Not Null constraint is also part of
the key constraint.
Explanation: In the above table, EID is the primary key, and the first and the last tuple
3. Entity Integrity Constraints
Entity Integrity constraints say that no primary key can take a NULL value, since
using the primary key we identify each tuple uniquely in a relation.
Explanation: In the above relation, EID is made the primary key, and the primary
key can’t take NULL values but in the third tuple, the primary key is null, so it is
violating Entity Integrity constraints.
4. Referential Integrity Constraints
• The Referential integrity constraint is specified between two relations or tables and used to
maintain the consistency among the tuples in two relations.
• This constraint is enforced through a foreign key, when an attribute in the foreign key of
relation R1 has the same domain(s) as the primary key of relation R2, then the foreign key of
R1 is said to reference or refer to the primary key of relation R2.
• The values of the foreign key in a tuple of relation R1 can take the values of the primary key
for some tuple in relation R2.
Explanation: In the above tables, the DNO of Table 1 is the foreign key, and DNO in Table 2 is
the primary key. DNO = 22 in the foreign key of Table 1 is not allowed because DNO = 22 is
not defined in the primary key of table 2. Therefore, Referential integrity constraints are
Con…
Whenever one of these operations are applied, integrity constraints specified on the
relational database schema must never be violated.
Relational Database Schemas
• A relational schema is a set of relational tables and associated items that are related to one
another.
• All of the database tables, views, indexes, domains, user roles, stored modules, and other items
that a user creates to fulfill the data needs of a particular enterprise or set of apply.
Components of a Relation Schema
• Relation Name: Name of the table that is stored in the database. It should be unique and related
to the data that is stored in the table.
• Attributes Name: Attributes specify the name of each column within the table
• Domains: The set of possible values for each attribute. It specifies the type of data that can be
stored in each column or attribute, such as integer, string, or date.
• Primary Key: The primary key is the key that uniquely identifies each tuple.
• Foreign Key: The foreign key is the key that is used to connect two tables. It refers to the
primary key of another table.
• Constraints: Rules that ensure the integrity and validity of the data, conations belong to one
4.3. Mapping ERD to Relational Schema
• To map an Entity-Relationship Diagram (ERD) to a relational schema, you transform entities into tables,
attributes into columns, and relationships into foreign keys, ensuring each table has a primary key and
relationships are correctly represented.
• To complete the mapping from an Entity Relationship Diagram (ERD) to relations, we must consider the entity
types, relationship types, and attributes that are specified for the model.
• How do you convert an entity-relationship diagram to a relational schema?
• Simply by breaking down entities, attributes, and relationships into tables (relations), columns, fields, and keys.
Entities to Tables:
•Strong Entities:
Each strong entity in the ERD becomes a separate table in the relational schema.
•Weak Entities:
Weak entities, which depend on other entities for their existence, also become tables, but their primary
key often includes a foreign key referencing the primary key of the identifying (strong) entity.
•Table Naming:
You can name the tables, but it's generally a good practice to use the same name as the entity, or a
2. Attributes to Columns:
•Simple Attributes:
Each simple attribute in the ERD becomes a column in the corresponding table.
•Composite Attributes:
Break down composite attributes into their simple components and create columns for each component.
•Derived Attributes:
Derived attributes, which can be calculated from other attributes, are generally not stored directly in the table,
but can be calculated on demand.
•Multivalued Attributes:
Multivalued attributes (attributes that can hold multiple values) are handled by creating a separate table with
a foreign key referencing the primary key of the original table.
3. Relationships to Foreign Keys:
•One-to-One (1:1) Relationships:
In a 1:1 relationship, you can either:
Include the primary key of one entity as a foreign key in the other entity's table . Merge the two tables into one .
•One-to-Many (1:N) Relationships:
The primary key of the "one" entity becomes a foreign key in the table representing the "many" entity.
Many-to-Many (M:N) Relationships:
Create a new table (often called a "junction" or "relationship" table) to represent the relationship. This table will
contain foreign keys referencing the primary keys of both entities involved in the relationship.
4. Primary Keys:
•Each table must have a primary key: that uniquely identifies each row in the table.
• Example
4.4. Normalization
• Database normalization
• is a series of steps followed to obtain a database design that allows for consistent
storage and efficient access of data in a relational database.
• It reduce data redundancy and the risk of data becoming inconsistent.
• It is a process of organizing data to reduce redundancy and improve data integrity by
structuring tables and relationships according to specific rules, aiming for efficiency
and consistency.
• Normalization is an important process in database design that helps improve the
database’s efficiency, consistency, and accuracy. It makes it easier to manage and
maintain the data and ensures that the database is adaptable to changing business needs.
• Normalization is the process of identifying the logical associations between data items
and designing a database that will represent such associations but without suffering the
anomalies which are
• Insertion Anomalies
• Deletion Anomalies
Con…
• Insertion Anomalies: Insertion anomalies occur when it is not possible to insert data
into a database because the required fields are missing or because the data is
incomplete. For example, if a database requires that every record has a primary key,
but no value is provided for a particular record, it cannot be inserted into the database.
• Deletion anomalies: Deletion anomalies occur when deleting a record from a
database and can result in the unintentional loss of data. For example, if a database
contains information about customers and orders, deleting a customer record may also
delete all the orders associated with that customer.
• Updating anomalies: Updating anomalies occur when modifying data in a database
and can result in inconsistencies or errors. For example, if a database contains
information about employees and their salaries, updating an employee’s salary in one
record but not in all related records could lead to incorrect calculations and reporting.
Con…
Common Normal Forms:
• As the father of the relational database approach, Codd created a series of rules called normal forms that help
define the organization.
• normal forms is various levels or steps in normalization.
•1NF (First Normal Form):
Each cell in a table should contain only a single value, eliminating repeating groups of data.
•2NF (Second Normal Form):
Builds upon 1NF and ensures that all non-key attributes are fully dependent on the primary
key, eliminating partial dependencies.
•3NF (Third Normal Form):
Builds upon 2NF and eliminates transitive dependencies, meaning no non-key attribute should
depend on another non-key attribute.
•BCNF (Boyce-Codd Normal Form):
exacting form of 3NF ensures that every determinant (attribute that determines another)
is a candidate key.
•4NF (Fourth Normal Form):
Addresses multi-valued dependencies, where a table has multiple independent sets of attributes.
•5NF (Fifth Normal Form):
The highest level of normalization, addressing join dependencies.
Con…
• Note: For most practical purposes, databases are considered normalized if they
follow to third normal form.
• All the normalization rules will eventually remove the anomalies(differences) that may
exist during data manipulation(management) after the implementation.
• The purpose of normalization is to reduce the chances for anomalies to occur in a
database.
• The level of complexity, strength of the rule and decomposition increases as we move
from one lower level normal form to the higher level normal form.
! ! !
E ND