Unit1.docx
Unit1.docx
Unit1.docx
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.
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
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.
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
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.
4) NoSQL Database
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
● 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.
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.
Only one user can access data at a Multiple users can access data at a
time. time.
User Access
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.
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
101 "Elmasri"
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
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.
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.
Data
Manipulation Data Definition Data Definition
Language Language Language
Command Command (DDL) Command (DDL)
Language (DML)
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
(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.
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.
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.