0% found this document useful (0 votes)
10 views22 pages

Unit 3

Uploaded by

shaikhsubuktgin
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)
10 views22 pages

Unit 3

Uploaded by

shaikhsubuktgin
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/ 22

UNIT-3

3.Relational Data Model

3.1 Introduction to Relational Data Model:

• Relational Model was proposed by E.F. Codd to model data in the form of relations or tables.
• After designing the conceptual model of Database using ER diagram, we need to convert the conceptual
model in the relational model which can be implemented using any RDBMS languages like Oracle,SQL,
MySQL etc. So we will see what Relational Model is.

What is Relational Model?


• Relational Model represents how data is stored in Relational Databases.

• A relational database stores data in the form of relations (tables).

• Relational Model (RM) represents the database as a collection of relations.


• A relation is nothing but a table of values.
• Every row in the table represents a collection of related data values.

3.2 Structure of Relational database and Important Terms:

1. Relation – In the Table model the, tables are saved in the relation format. It is stored along with its
entities. A reation has two properties rows and columns. Rows represent records and columns represent
attributes.
2. Tuple – It is nothing but a single row of a table, which contains a single record.
3. Attribute: Each column in a Table. Attributes are the properties which define a relation. e.g.,
Student_Rollno, NAME,etc.
4. Cardinality: Total number of rows present in the Table.
5. Degree: The total number of attributes which in the relation is called the degree of the relation.
6. Domain: A domain is a set of allowable values for one or more attributes.

3.2 Integrity Constraints over Relation

• Integrity constraints are used to ensure accuracy and consistency of the data in a relational
database.
• Integrity constraints are set of rules that the database is not permitted to violate.
• Constraints may apply to each attribute or they may apply to relationships between tables.
• Integrity constraints ensure that changes (update, deletion, insertion) made to the database by
authorized users do not result in a loss of data consistency.
• Thus, integrity constraints guard against accidental damage to the database.
• Example - A blood group must be 'A' or 'B' or 'AB' or '0' only (can not any other values else).

*TYPES OF INTEGRITY CONSTRAINT :

❖ Domain Constraint
❖ Entity Integrity Constraint
❖ Referential Integrity Constraint
❖ Key Constraints
1. Domain Constraints

Domain constraints de-fines the domain or the valid set of values for an

attribute.

2. Entity Integrity Constraints


The entity integrity constraint states that primary key value can't be null.
This is because the primary key value is used to identify individual rows in relation and if the primary key
has a null value, then we can't identify those rows.
A table can contain a null value other than the primary key field
3. Referential Integrity Constraints
• A referential integrity constraint is specified between two tables.
• Referential Integrity constraint is enforced when a foreign key references the primary key of a
table.
• In the Referential integrity constraints, if a foreign key in Table 1 refers to the Primary Key of
Table 2, then either every value of the foreign Key in Table 1 must be available in primary key
value of Table 2 or it must be null.

• The rules are:


• You can't delete a record from a primary table if matching records exist in a related table.
• You can't change a primary key value in the primary table if that record has related records.
• You can't insert a value in the foreign key field of the related table that doesn't exist in the primary
key of the primary table.
• However, you can enter a Null value in the foreign key, specifying that the records are unrelated.
4. Key Constraints
• An entity set can have multiple keys or candidate keys (minimal superkey), but out of which one
key will be the primary key.
• Key constraint specifies that in any relation-
• All the values of primary key must be unique.
• The value of primary key must not be null.

3.4 Logical Database Design: ER to Relational

Conversion of ER to relational model –


Consider the following diagram to convert into relation data model,

Diagram – STUDENT Entity

The basic rules for converting the ER diagrams into relational model are,
1) Convert all the entities in the diagram to tables –
All the entities represented in the rectangular box in the ER diagram become separate tables in the
database. In the above diagram, STUDENT is an entity convert into a separate table.

Table -- STUDENT

2) All single valued attributes of an entity is converted to a column of the table –


All the attributes, whose value at any instance of time is unique, are considered as columns of that table.
In the STUDENT Entity, ROLLNO, CITY and DOB form the columns of STUDENT table.
ROLLNO CITY DOB

Table – STUDENT
3) Key attribute in the ER diagram becomes the primary key of the table –
In above diagram, ROLLNO is the key attribute of the STUDENT entity. Hence we consider it as the
primary key of STUDENT table.

ROLLNO CITY DOB

Table – STUDENT

4) If any composite attributes are available then replaced by component attributes –


In the above diagram, student’s NAME is a composite attribute. It has FIRSTNAME and LASTNAME.
These attributes are merged into STUDENT table as individual columns.

ROLLNO FIRSTNAME LASTNAME CITY DOB

Table – STUDENT
5) Any multi-valued attributes are converted into new table –
A MOBILE_NO of the STUDENT entity is a multivalued attribute. Any student can have any number
of mobile numbers.
So, we cannot represent multiple values in a single column of STUDENT table. Hence we create a
separate table CONTACT with ROLLNO and MOBILE_NO as its columns.

ROLLNO FIRSTNAME LASTNAME CITY DOB

Table – STUDENT

ROLLNO MOBILE_NO

Table – CONTACT

6) Ignore derived attribute, since it can be calculated at any time –


In the above STUDENT entity, AGE can be derived at any point of time by calculating the difference
between DOB and current date. Hence we need not create a column for this attribute. It reduces the duplicity in
the database.

ROLLNO FIRSTNAME LASTNAME CITY DOB

Table–STUDENT
3.5 The Relational Algebra

• Relational algebra is a procedural query language, which takes instances of relations as


input and yields instances of relations as output.
• It uses operators to perform queries.
• An operator can be either unary or binary.
• They accept relations as their input and yield relations as their output.
• Relational algebra is performed recursively on a relation and intermediate results are
also considered relations.
• Relation algebra operationas work on one or more relations to definne another reation
without changing the original relations.
• The fundamental operations of relational algebra are as follows −

✓ Select
✓ Project
✓ Union
✓ Set different
✓ Intersection
✓ Cartesian Produt
✓ Natural Join
*Exmple: 01
*Exmple: 02

*Exmple: 03
*Exmple: 04

*Exmples:
*Example: 01
*Example: 02

*Example: 03
*Example: 04
*Example:
*Example:
*Example:
*Example:
*Example:

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy