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

Unit1.docx

Download as pdf or txt
Download as pdf or txt
Download as pdf or txt
You are on page 1/ 33

DBMS:

1) Data: Raw, Facts and figures having no particular meaning (e.g. 1, ABC, 19 )
Example: Text, audio, video, image etc.
2) Information: if we organize them in the following way, then they collectively
represent meaningful information. Processed, meaningful, usable data.

Roll no. Name age


1 ABC 19

3) Database: A database is a collection of interrelated/Similar data. For Example,


a university database organizes the data about students, faculty, admin staff, etc.
There are many databases available like MySQL, Sybase, Oracle, MongoDB,
Informix, PostgreSQL, SQL Server, etc.
4) DBMS: A Database Management System (DBMS) is a software system that is
designed to manage and organize data in a structured manner. It allows users to
create, modify, and query a database, as well as manage the security and access
controls for that database. DBMS provides an environment to store and retrieve
data in convenient and efficient manner.
Evolution of Databases
The database has completed more than 50 years of journey of its evolution from
flat-file system to relational and objects relational systems.
File-Based
1968 was the year when File-Based database were introduced. In file-based databases,
data was maintained in a flat file.
Disadvantages of File system:
1) Data redundancy: same data stored in two different files
2) Data inconsistency: if the same data is updated in one file but not in another.
3) Difficulty in accessing data
4) Security problem
5) Scalability Issues: Managing large amounts of data in a file system is difficult
6) Backup and Recovery: While file systems may require manual backup processes.
Hierarchical Data Model

1968-1980 was the era of the Hierarchical Database. Prominent hierarchical database model
was IBM's first DBMS. It was called IMS (Information Management System).

Imagine a database for a retail company. The data might be organized as follows:

● Level 1: Company

o Level 2: Departments (e.g., Electronics, Clothing, Grocery)

▪ Level 3: Categories (e.g., Laptops, Phones under Electronics)

▪ Level 4: Products (e.g., Specific Laptop or Phone models)

Relational Database

1970 - Present: It is the era of Relational Database and Database Management. In 1970, the
relational model was proposed by E.F. Codd.

Relational database model has two main terminologies called instance and schema.

The instance is a table with rows or columns

Schema specifies the structure like name of the relation, type of each column and name.
Types of Databases
There are various types of databases used for storing different varieties of data:

1) Centralized Database

A Centralized Database is a database where all data is stored in one central location,
like a single computer or server. All users and applications access data from this central
place.

● Example: Think of a library with one central catalog that has information about
all the books available. If anyone wants to find a book, they go to this central
catalog.

2) Distributed Database

A Distributed Database stores data across multiple locations or computers, which


could be in different places. This helps improve data availability, reliability, and speed.

● Example: An international company with offices in different countries might


store customer data in databases located in each country. Each office can access
the local data quickly, while the data is still part of a larger distributed system.

3) Relational Database
A Relational Database organizes data into tables with rows and columns. Each table
represents a different entity (like a person or a product), and relationships between these
entities are established using keys.

● Example: A school management system where one table contains student


information (like name, age, and student ID), and another table contains course
information (like course name and course ID). A third table links students to
courses they are enrolled in, using their IDs.
● Common Relational Databases: MySQL, Microsoft SQL Server, Oracle.

4) NoSQL Database

A NoSQL Database is designed to store large volumes of unstructured or


semi-structured data. It does not use traditional table-based structure like relational
databases. Instead, it can store data as documents, key-value pairs, graphs, etc.

● Example: A social media application like Facebook uses a NoSQL database to


store user profiles, posts, comments, likes, and other activities. This data can be
different for each user and doesn't fit neatly into rows and columns.
● Common NoSQL Databases: MongoDB (document-oriented), Cassandra
(column-family), Redis (key-value), Neo4j (graph).

5) Cloud Database

A Cloud Database is a type of database that runs on a cloud computing platform. Data
is stored and managed in a virtual environment, allowing for scalability, flexibility, and
cost savings.

● Example: A startup company uses Amazon Web Services (AWS) to host their
customer data in a cloud database. This way, they don't need to invest in
expensive hardware, and they can scale up or down based on their needs.
● Popular Cloud Platforms: AWS, Microsoft Azure, Google Cloud SQL.

6) Object-Oriented Databases

An Object-Oriented Database stores data in the form of objects, like in object-oriented


programming. Each object includes data (attributes) and the methods (functions) that
can be performed on the data.

● Example: A multimedia database that stores different types of media (like text,
audio, video) in objects. Each media type has its own set of properties and
methods to play, edit, or modify.

7) Hierarchical Databases

A Hierarchical Database stores data in a tree-like structure, where each record has a
single parent, but may have multiple children. It is like an organizational chart.
● Example: A file system on your computer is a good example of a hierarchical
database. You have a root folder, which can have multiple subfolders, and each
subfolder can have more folders or files inside it.

8) Network Databases

A Network Database organizes data in a graph structure where records can have
multiple parent and child nodes, allowing for many-to-many relationships.

● Example: A flight reservation system where one airport (node) is connected to


multiple airlines (other nodes), and each airline node can be connected to
multiple flight routes (other nodes).

9) Personal Database

A Personal Database is a small database meant for use by a single person on a personal
computer. It is usually used for managing personal data like contact lists, expenses, or
notes.

● Example: A simple Microsoft Excel spreadsheet used by someone to track their


monthly expenses is an example of a personal database. It is managed and stored
on their own computer.

File System VS DBMS

Basics File System DBMS

Redundant data can be present in a In DBMS there is no redundant


Data
file system. data.
Redundancy

It doesn’t provide Inbuilt It provides in house tools for


mechanism for backup and backup and recovery of data even
Backup and
recovery of data if it is lost. if it is lost.
Recovery

There is no efficient query Efficient query processing is there


Query
processing in the file system. in DBMS.
processing

There is less data consistency in the


There is more data consistency.
file system.
Consistency
Basics File System DBMS

It is less complex as compared to It has more complexity in handling


DBMS. as compared to the file system.
Complexity

DBMS has more security


File systems provide less security in
mechanisms as compared to file
Security comparison to DBMS.
systems.
Constraints

It has a comparatively higher cost


It is less expensive than DBMS.
than a file system.
Cost

Only one user can access data at a Multiple users can access data at a
time. time.
User Access

Data is distributed in many files. So, Due to centralized nature data


it is not easy to share data. sharing is easy
Sharing

Cobol, C++ Oracle, SQL Server


Example

Advantage of DBMS
Controls redundancy
It stores all the data in a single database file, so it can control data redundancy.
Data sharing
An authorized user can share the data among multiple users.
Backup
It provides Backup and recovery subsystem. This recovery system creates automatic
data from system failure and restores data if required.

Disadvantage of DBMS
Size
It occupies large disk space and large memory to run efficiently.
Cost
DBMS requires a high-speed data processor and larger memory to run DBMS software,
so it is costly.
Complexity
DBMS creates additional complexity and requirements.

DBMS Architecture
o The DBMS design depends upon its architecture. DBMS architecture depends
upon how users are connected to the database to get their request done.

But logically, database architecture is of two types like: 2-tier architecture and 3-tier
architecture.
1-Tier Architecture
o In this architecture, the database is directly available to the user. It means the
user can directly sit on the DBMS and uses it.
o Any changes done here will directly be done on the database itself. It doesn't
provide a handy tool for end users.
o The 1-Tier architecture is used for development of the local application, where
programmers can directly communicate with the database for the quick
response.
o A simple real example of a 1-Tier architecture is Microsoft Excel being used to
store and manage data.
2-Tier Architecture
o The 2-Tier architecture is same as basic client-server. In the two-tier
architecture, applications on the client end can directly communicate with the
database at the server side. For this interaction, API's like: ODBC, JDBC are
used.
o The user interfaces and application programs are run on the client-side.
o The server side is responsible to provide the functionalities like: query
processing and transaction management.
o To communicate with the DBMS, client-side application establishes a
connection with the server side.

Fig: 2-tier Architecture


Example:
1. A librarian uses the client application to search for a book.
2. The client application sends an SQL query (e.g., SELECT * FROM books
WHERE title = 'The Great Gatsby') to the database server.
3. The database server processes the query and retrieves the relevant data.
4. The server sends the result (the details of the book "The Great Gatsby") back to
the client application.
5. The client application displays the result to the librarian.
3-Tier Architecture
o The 3-Tier architecture contains another layer between the client and server. In
this architecture, client can't directly communicate with the server.
o The application on the client-end interacts with an application server which
further communicates with the database system.
o End user has no idea about the existence of the database beyond the application
server. The database also has no idea about any other user beyond the
application.
o The 3-Tier architecture is used in case of large web application.
Example: A web-based e-commerce application.
● Client Side: A web browser that sends a request to a web server (like a shopping
cart in an online store).
● Application Server: A web server running the business logic (like Node.js,
Django, or Spring Boot) processes the request, interacts with the database, and
sends a response back to the client.
● Database Layer: A relational database server like PostgreSQL, SQL Server, or
MongoDB stores all the data (like user details, product information, order
details, etc.)

Fig: 3-tier Architecture


Data Model, Schema, and Instance in DBMS
1. Data Model
● Definition: A data model is a conceptual framework that defines how data is
structured, stored, and manipulated within a database management system
(DBMS).
1. Hierarchical Data Model
The Hierarchical Data Model organizes data in a tree-like structure, where
each record (also called a node) has a single parent and potentially multiple
children, forming a hierarchy.
● Example: Consider an organization where employees are organized into
departments. The structure might look like this:
o Company
▪ Department A
▪ Employee 1
▪ Employee 2
▪ Department B
▪ Employee 3
▪ Employee 4
In this example, "Company" is the root node, and it has two child nodes
("Department A" and "Department B"). Each department has further child nodes
representing employees.
2. Network Data Model
The Network Data Model extends the hierarchical model by allowing multiple
parent nodes, supporting many-to-many relationships. In this model, data is
organized as a graph, where records are nodes, and relationships between them
are edges.
● Example: Consider a database of a university, where a "Course" can be taken by
multiple "Students", and each "Student" can enroll in multiple "Courses".

o Course
▪ Course 1: Enrolled by Student 1, Student 2
▪ Course 2: Enrolled by Student 2, Student 3
o Student
▪ Student 1: Enrolled in Course 1
▪ Student 2: Enrolled in Course 1, Course 2
▪ Student 3: Enrolled in Course 2
In this model, "Course" and "Student" are nodes that have many-to-many
relationships.
3. Relational Data Model
The Relational Data Model organizes data into tables (relations) consisting of
rows (tuples) and columns (attributes). Relationships between tables are
established using keys (primary keys and foreign keys). This model is the most
widely used due to its simplicity and flexibility.
● Example: Consider a database for an online bookstore with two tables: Books
and Authors.
o Books Table:
BookID Title AuthorID

1 "Database Systems" 101

2 "Learning Python" 102


o Authors Table:
AuthorID Name

101 "Elmasri"

102 "Mark Lutz"


Here, the Books table has a foreign key (AuthorID) that references the primary
key (AuthorID) in the Authors table. This relationship allows linking books to
their authors.
4. Object-Oriented Data Model
The Object-Oriented Data Model represents data in the form of objects,
similar to how object-oriented programming languages (like Java or Python)
represent entities. Each object contains data in the form of fields (attributes) and
methods (operations).
● Example: Consider a database for a car rental company where each car is an
object.
o Car Object:
▪ Attributes: CarID, Brand, Model, Year, RentalPrice
▪ Methods: RentCar(), ReturnCar(), CalculateRentalFee()

5. Entity-Relationship (ER) Model


The Entity-Relationship (ER) Model is a conceptual data model that represents
data using entities (objects or concepts), attributes (properties of entities), and
relationships (associations between entities).
● Example: Consider a university database:
o Entities:
▪ Student (with attributes: StudentID, Name, Email)
▪ Course (with attributes: CourseID, CourseName, Credits)
o Relationships:
▪ Enrolls: Represents a relationship between Student and Course.
6. Document Data Model
The Document Data Model is used primarily in NoSQL databases, where data
is stored in a document format, often as JSON or XML. Each document is a
self-contained unit, and fields within the document can store different data types,
arrays, and even nested documents.
● Example: Consider a User document in a MongoDB database:
{
"UserID": "123",
"Name": "John Doe",
"Email": "[email protected]",
"Orders": [
{
"OrderID": "456",
"Date": "2024-09-12",
"Items": ["Item1", "Item2"]
},
{
"OrderID": "789",
"Date": "2024-09-15",
"Items": ["Item3"]
}
]
}

2. Schema
In DBMS (Database Management System), a schema is a logical structure that defines
the organization of data within the database. It provides a blueprint of how data is
stored, organized.
Example of a Database Schema:
Let's consider an example schema for a University Database that manages information
about students, courses.
Schema for a University Database:
1. Students Table:
Column
Data Type Constraint Description
Name

PRIMARY KEY, NOT Unique identifier for each


StudentID INT
NULL student

FirstName VARCHAR(50) NOT NULL Student's first name

LastName VARCHAR(50) NOT NULL Student's last name

DateOfBirth DATE Student's date of birth

Email VARCHAR(100) UNIQUE Student's email address


2. Courses Table:
Column
Data Type Constraint Description
Name

PRIMARY KEY, NOT Unique identifier for each


CourseID INT
NULL course

CourseName VARCHAR(100) NOT NULL Name of the course

Number of credits for the


Credits INT
course

Three schema Architecture


o The three schema architecture is also called ANSI/SPARC architecture or
three-level architecture.
o This framework is used to describe the structure of a specific database system.
o The three schema architecture contains three-levels. It breaks the database down
into three different categories.
Physical Schema:
● Definition: Describes the physical storage of data on the hardware. It defines
how the data is stored in blocks of storage (like hard disks, SSDs), indexing
mechanisms, file structures, and other physical aspects.
Logical Schema:
● Definition: Describes the logical structure of the entire database. It defines
tables, columns, data types, relationships, and constraints but does not specify
how the data is stored physically.
View Schema (External Schema):
● Definition: Also known as an external schema or subschema, it represents the
customized views of the data for different users or user groups. These views are
created to provide a tailored view of the database to different users according to
their needs and access permissions.
3. Instance
● Definition: An instance refers to the actual content of a database at a specific
point in time. It represents a snapshot of the data that conforms to the database
schema.
Relationship Between Schema and Instance
● Schema: A schema is a design or structure of the database that defines the
logical organization of data. It is like a blueprint and does not change frequently.
o Example: Consider a schema that defines a Customer table:
CREATE TABLE Customer (
CustomerID INT PRIMARY KEY,
Name VARCHAR(100),
Email VARCHAR(100),
PhoneNumber VARCHAR(15),
Address VARCHAR(255)
);
o Here, the schema defines the structure of the table, including the column
names, data types, and constraints.
● Instance: An instance is the actual content of the database at a given time,
which includes the data stored in tables according to the schema.
o Example: An instance of the Customer table at a specific time might look
like:

CustomerID Name Email PhoneNumber Address


John [email protected] 123 Elm
1 1234567890
Doe m St, City
Jane [email protected] 456 Oak
2 9876543210
Smith m St, Town

Data Independence:
o Data independence can be explained using the three-schema architecture.
o Data independence refers characteristic of being able to modify the schema at
one level of the database system without altering the schema at the next higher
level.
There are two types of data independence:
1. Logical Data Independence
o Logical data independence refers characteristic of being able to change the
conceptual schema without having to change the external schema.
o Logical data independence is used to separate the external level from the
conceptual view.
o If we do any changes in the conceptual view of the data, then the user view of
the data would not be affected.
o Logical data independence occurs at the user interface level.
2. Physical Data Independence
o Physical data independence can be defined as the capacity to change the internal
schema without having to change the conceptual schema.
o If we do any changes in the storage size of the database system server, then the
Conceptual structure of the database will not be affected.
o Physical data independence is used to separate conceptual levels from the
internal levels.
o Physical data independence occurs at the logical interface level.
Database Languages in DBMS
o Database languages can be used to read, store and update the data in the
database.

Types of Database Languages

1. Data Definition Language (DDL)


o DDL stands for Data Definition Language. It is used to define database
structure.
i) CREATE: Creates a new table or database object.
● Example:
CREATE TABLE Employees (
EmployeeID INT PRIMARY KEY,
FirstName VARCHAR(50),
LastName VARCHAR(50),
Position VARCHAR(50),
Salary DECIMAL(10, 2)
);
ii) ALTER: Modifies an existing database object (like adding or deleting columns).
● Example:
ALTER TABLE Employees ADD DateOfBirth DATE;

iii) DROP: Deletes a table or database object.


● Example:
DROP TABLE Employees;
● This command deletes the "Employees" table from the database.

iv) TRUNCATE: Removes all records from a table but keeps the structure of the table.
● Example:
TRUNCATE TABLE Employees;
This command removes all the records from the "Employees" table but retains the
table's structure.

2. Data Manipulation Language (DML)


DML stands for Data Manipulation Language. It is used for accessing and manipulating
data in a database
i)INSERT: Adds new records to a table.
● Example:
INSERT INTO Employees (EmployeeID, FirstName, LastName, Position, Salary)
VALUES (1, 'John', 'Doe', 'Manager', 75000.00);
ii) UPDATE: Modifies existing records in a table.
● Example:
UPDATE Employees SET Salary = 80000.00 WHERE EmployeeID = 1;
iii) DELETE: Removes records from a table.
● Example:
DELETE FROM Employees WHERE EmployeeID = 1;
iv) SELECT: Retrieves data from a table.
● Examples:
SELECT * FROM Employees;
Retrieves all columns and rows from the "Employees" table.
SELECT FirstName, LastName FROM Employees WHERE Salary > 60000;
Retrieves the FirstName and LastName of employees whose salary is greater than
60,000.
3. Data Control Language (DCL)
o DCL stands for Data Control Language. It is used to retrieve the stored or saved
data.
i)GRANT: Gives permissions to a user.
● Example:
GRANT SELECT, INSERT ON Employees TO User1;
This command grants User1 the permissions to SELECT and INSERT data into the
"Employees" table.
ii) REVOKE: Removes permissions from a user.
● Example:
REVOKE INSERT ON Employees FROM User1;
This command revokes the INSERT permission on the "Employees" table from User1.
4. Transaction Control Language (TCL)
TCL is used to run the changes made by the DML statement. TCL can be grouped into a
logical transaction.
i) COMMIT: Saves all changes made during the current transaction.
● Example
INSERT INTO Employees (EmployeeID, FirstName, LastName, Position, Salary)
VALUES (2, 'Jane', 'Smith', 'Developer', 60000.00);
COMMIT;
This command inserts a new record into the "Employees" table and saves the changes to
the database.
ii) ROLLBACK: Reverts all changes made during the current transaction.
● Example
DELETE FROM Employees WHERE EmployeeID = 2;
ROLLBACK;
This command attempts to delete the employee with EmployeeID 2 but undoes
the operation due to ROLLBACK.
Comparision Between Delete Drop and Truncate

Parameter Delete Drop Truncate

Data
Manipulation Data Definition Data Definition
Language Language Language
Command Command (DDL) Command (DDL)
Language (DML)

Used to delete Used to delete


Used to delete
entire content of entire content of
content in rows
table along with the table leaving the
of a table.
Purpose table structure. table structure.

DELETE
FROM DROP table TRUNCATE table
table_name <table_name>; <table_name>;
WHERE
Syntax condition;
Keys
o Keys play an important role in the relational database.
o It is used to uniquely identify any record or row of data from the table. It is also
used to establish and identify relationships between tables.
o For example, ID is used as a key in the Student table because it is unique for
each student. In the PERSON table, passport_number, license_number, SSN are
keys since they are unique for each person.

1. Primary Key
A primary key is a column (or a combination of columns) in a table that
uniquely identifies each row in that table. The primary key must be unique for
each row, and it cannot contain NULL values.

(Students):
Student_ID Name Age Email

1 Abhi 21 [email protected]

2 Rahul 22 [email protected]

3 Priya 20 [email protected]

● Student_ID Alone:
o In this table, Student_ID is the primary key.
o Uniqueness: Each student has a unique Student_ID. No two students can
have the same Student_ID.
o Non-null: Every student must have a valid Student_ID. It cannot be
NULL.
2. Candidate Key
A candidate key is a column or a set of columns that can qualify as a unique
key in a table. A table can have more than one candidate key, but only one of
them can be chosen as the primary key.
(Students):
Student_ID Name Age Email

1 Abhi 21 [email protected]

2 Rahul 22 [email protected]

3 Priya 20 [email protected]
● Student_ID Alone:
o Student_ID is a candidate key because it uniquely identifies each student.
● Email Alone:
o Email is also a candidate key because each student has a unique email
address.
● Both Student_ID and Email are candidate keys because they both satisfy the
conditions of being unique and non-null.

3. Super Key
A super key is any combination of columns that can uniquely identify a row in
the table. A super key may include extra columns that aren’t needed to uniquely
identify the record.
(Students):
Student_ID Name Email Age

1 Abhi [email protected] 21

2 Rahul [email protected] 22

3 Priya [email protected] 20

● Super Key 1: Student_ID alone is a super key because it uniquely identifies


each student.
● Super Key 2: A combination of Student_ID + Name is also a super key because
the combination still uniquely identifies each student. Even though Student_ID
alone is enough, adding Name still maintains uniqueness.
4. Alternate Key
An alternate key is any candidate key that is not chosen to be the primary key.
Example:
If Student_ID is chosen as the primary key, then Email becomes the alternate
key, since it was a candidate key but not selected as the primary key.

(Students):
Student_ID Name Email Age

1 Ankit [email protected] 21

2 Rahul [email protected] 22

3 Priya [email protected] 20
● Both Student_ID and Email are candidate keys.
● If Student_ID is chosen as the primary key, Email becomes an alternate key.

5. Foreign Key
A foreign key is a column (or a combination of columns) that creates a
relationship between two tables. It refers to the primary key of another table,
ensuring the integrity of the data between the tables.

Students Table:
Student_ID Name

1 Abhi

2 Rahul
Course_Enrollment Table:
Enrollment_I Student_I Course_I Enrollment_Dat
D D D e

1 1 101 2024-01-10

2 2 102 2024-01-18
● In the Course_Enrollment table, Student_ID is a foreign key that refers to the
Student_ID in the Students table.
● This means that each Student_ID in Course_Enrollment must correspond to an
existing student in the Students table.
6. Composite Key
A composite key is a combination of two or more columns that, together,
uniquely identify a row in a table. Neither column alone can uniquely identify a
record, but together they can.

Example:
Consider a table, Course_Enrollment, which records which students are enrolled
in which courses:
Student_ID Course_ID Enrollment_Date

1 101 2024-01-10

1 102 2024-01-15

2 101 2024-01-11

2 102 2024-01-18
● Student_ID alone cannot uniquely identify a row because a student can enroll in
multiple courses.
● Course_ID alone cannot uniquely identify a row because a course can have
multiple students.
● However, the combination of Student_ID and Course_ID together forms a
composite key because each pair of Student_ID and Course_ID is unique. For
example:
o (1, 101) uniquely identifies Student 1 enrolled in Course 101.
o (2, 101) uniquely identifies Student 2 enrolled in Course 101.
ER (Entity Relationship) Model
o ER model stands for an Entity-Relationship model. It is a high-level data model.
This model is used to define the data elements and relationship for a specified
system.
o It develops a conceptual design for the database. It also develops a very simple
and easy to design view of data.
o In ER modeling, the database structure is portrayed as a diagram called an
entity-relationship diagram.
For example, Suppose we design a school database. In this database, the student will be
an entity with attributes like address, name, id, age, etc. The address can be another
entity with attributes like city, street name, pin code, etc and there will be a relationship
between them.

Symbols Used in ER Model


Component of ER Diagram

1. Entity:
An entity may be any object, class, person or place. In the ER diagram, an entity can be
represented as rectangles.
● Strong Entity: A strong entity is an entity that can exist independently and has a
primary key that uniquely identifies each instance.
Example:
o Employee: In a company database, an employee entity can exist on its
own. Each employee has a unique EmployeeID, which is the primary
key.
▪ Attributes for Employee: EmployeeID, Name, Position, etc.
● Weak Entity: A weak entity cannot exist on its own and depends on a strong
entity. It doesn't have a primary key of its own and is identified using the strong
entity's primary key along with its own attributes.
Example:
For Example, A company may store the information of dependents (Parents, Children,
Spouse) of an Employee. But the dependents can’t exist without the employee. So
Dependent will be a Weak Entity Type and Employee will be Identifying Entity type
for Dependent, which means it is Strong Entity Type .
2. Attribute
The attribute is used to describe the property of an entity. Eclipse is used
to represent an attribute.

For example, id, age, contact number, name, etc. can be attributes of a
student.

a. Key Attribute
The key attribute is used to represent the main characteristics of an entity. It represents a
primary key. The key attribute is represented by an ellipse with the text underlined.

b. Composite Attribute
An attribute that composed of many other attributes is known as a composite attribute.
The composite attribute is represented by an ellipse, and those ellipses are connected
with an ellipse.
c. Multivalued Attribute
An attribute can have more than one value. These attributes are known as a multivalued
attribute. The double oval is used to represent multivalued attribute.
For example, a student can have more than one phone number.

d. Derived Attribute
An attribute that can be derived from other attribute is known as a derived attribute. It
can be represented by a dashed ellipse.
For example, A person's age changes over time and can be derived from another
attribute like Date of birth.
3. Relationship and Relationship Set
A relationship is used to describe the relation between entities. Diamond or rhombus is
used to represent the relationship.
A Relationship Type represents the association between entity types. For example,
‘Enrolled in’ is a relationship type that exists between entity type Student and Course.
In ER diagram, the relationship type is represented by a diamond and connecting the
entities with lines.

A set of relationships of the same type is known as a relationship set. The following
relationship set depicts S1 as enrolled in C2, S2 as enrolled in C1, and S3 as registered
in C3.

Types of relationship are as follows:


a. One-to-One Relationship
When only one instance of an entity is associated with the relationship, then it is known
as one to one relationship.
For example, A female can marry to one male, and a male can marry to one female.
Another example is the relationship between the director of the school and the school
because one school can have a maximum of one director, and one director can belong to
only one school.
b. One-to-many relationship
When only one instance of the entity on the left, and more than one instance of an entity
on the right associates with the relationship then this is known as a one-to-many
relationship.
For example, Scientist can invent many inventions, but the invention is done by the
only specific scientist.

c. Many-to-one relationship
When more than one instance of the entity on the left, and only one instance of an entity
on the right associates with the relationship then it is known as a many-to-one
relationship.
For example, Student enrolls for only one course, but a course can have many students.

For example, there are multiple patients in a hospital who are served by a single doctor,
so the relationship between patients and doctors can be represented by Many to one
Cardinality.
d. Many-to-many relationship
When more than one instance of the entity on the left, and more than one instance of an
entity on the right associates with the relationship then it is known as a many-to-many
relationship.
For example, Employee can assign by many projects and project can have many
employees.

Mapping Constraints
Mapping constraints define the number of entities that can participate in a relationship.
There are four types of Cardinality Mapping.
1. One to one
2. Many to one
3. One to many
4. Many to many

Participation Constraint
Participation Constraint is applied to the entity participating in the
relationship set.
1. Total Participation – Each entity in the entity set must participate in
the relationship. If each student must enroll in a course, the
participation of students will be total. Total participation is shown by
a double line in the ER diagram.
2. Partial Participation – The entity in the entity set may or may NOT
participate in the relationship. If some courses are not enrolled by any
of the students, the participation in the course will be partial.

You might also like