0% found this document useful (0 votes)
32 views47 pages

Unit-1 - Notes Dbms

Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
0% found this document useful (0 votes)
32 views47 pages

Unit-1 - Notes Dbms

Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
Download as pdf or txt
You are on page 1/ 47

Unit -1: Overview, Database System vs File System, Database System Concept and

Architecture, Data Model Schema and Instances, Data Independence and Database Language
and Interfaces, Data Definitions Language, DML, Overall Database Structure. Data Modeling
Using the Entity Relationship Model: ER Model Concepts, Notation for ER Diagram, Mapping
Constraints, Keys, Concepts of Super Key, Candidate Key, Primary Key, Generalization,
Aggregation, Reduction of an ER Diagrams to Tables, Extended ER Model, Relationship of
Higher Degree.

INTRODUCTION TO DBMS:

What is data?
 Data is nothing but facts and statistics stored or free flowing over a
network, generallyit's raw and unprocessed.
 Data becomes information when it is processed, turning it into something
meaningful.
 What is database: The database is a collection of inter-related data
which is used toretrieve, insert and delete the data efficiently.
 It is also used to organize the data in the form of a table, schema,
views, and reports,etc.
 Using the database, you can easily retrieve, insert, and delete the information.
 For example: The college Database organizes the data about the
admin, staff, studentsand faculty etc.
What is dbms?

 A DBMS is software that allows creation, definition and


manipulation of database, allowing users to store, process and
analyse data easily.
 DBMS provides us with an interface or a tool, to perform various
operations like creating database, storing data in it, updating data,
creating tables in the database anda lot more.
 DBMS also provides protection and security to the databases.
 It also maintains data consistency in case of
multiple users. Here are some examples of
popular DBMS used these days:
 MySql
 Oracle
 SQL Server
 IBM DB2
DATABASE APPLICATIONS – DBMS:
 Applications where we use Database Management Systems are:
 Telecom: There is a database to keeps track of the information
regarding calls made, network usage, customer details etc.

 Industry: Where it is a manufacturing unit, warehouse or distribution


centre, each oneneeds a database to keep the records of ins and outs
 Banking System: For storing customer info, tracking day to day
credit and debit transactions, generating bank statements etc.
 Sales: To store customer information, production information and invoice details.
 Airlines: To travel though airlines, we make early reservations;
this reservationinformation along with flight schedule is stored
in database.
 Education sector: Database systems are frequently used in schools and
colleges to store and retrieve the data regarding student details, staff
details, course details, examdetails, payroll data, attendance details,
fees details etc.
PURPOSE OF DATABASE SYSTEMS

 The main purpose of database systems is to manage the data. Consider a


university that keeps the data of students, teachers, courses, books etc. To
manage this data we need to store this data somewhere where we can add new
data, delete unused data, update outdated data, retrieve data, to perform these
operations on data we need a Database management system that allows us to
store the data in such a way so that allthese operations can be performed on the
data efficiently.
Characteristics of DBMS

 Data stored into Tables: Data is never directly stored into the
database. Data is stored into tables, created inside the database.
 Reduced Redundancy: In the modern world hard drives are very cheap,
but earlier when hard drives were too expensive, unnecessary
repetition of data in database was abig problem. But DBMS follows
Normalisation which divides the data in such a way that repetition is
minimum.
 Data Consistency: On Live data, i.e. data that is being continuosly
updated and added, maintaining the consistency of data can become a
challenge. But DBMS handles it all by itself.
 Support Multiple user and Concurrent Access: DBMS allows
multiple users to workon it(update, insert, delete data) at the same
time and still manages to maintain the data consistency.

 Query Language: DBMS provides users with a simple Query


language, using whichdata can be easily fetched, inserted, deleted
and updated in a database.

Advantages of DBMS

 Controls database redundancy: It can control data redundancy because


it stores all thedata in one single database file and that recorded data is
placed in the database.
 Data sharing: In DBMS, the authorized users of an organization
can share the dataamong multiple users.
 Easily Maintenance: It can be easily maintainable due to the
centralized nature of thedatabase system.
 Reduce time: It reduces development time and maintenance need.
 Backup: It provides backup and recovery subsystems which create
automatic backupof data from hardware and software failures and
restores the data if required.
 multiple user interface: It provides different types of user
interfaces like graphicaluser interfaces, application program
interfaces

Disadvantages of DBMS

Cost of Hardware and Software: It requires a high speed of data processor and largememory size to run
DBMS software.

 Size: It occupies a large space of disks and large memory to run them efficiently.
 Complexity: Database system creates additional complexity and requirements.
 Higher impact of failure: Failure is highly impacted the database
because in most of the organization, all the data stored in a single
database and if the database is damageddue to electric failure or
database corruption then the data may be lost forever.
Difference Between Traditional Filesystem and Database Approach

DBMS File System

DBMS is a collection of data. In File system is a collection of data. In this


DBMS, theuser is not required to write system, theuser has to write the procedures for
the procedures. managing the database.

Searching data is easy in Dbms Searching is difficult in File System

Dbms is structured data Files are unstructured data

No data redundancy in Dbms Data redundancy is there in file system

Memory utilisation well in dbms Memory utilisation poor in file system

No data inconsistency in dbms Inconsistency in file system

DBMS gives an abstract view of data that File system provides the detail of the data
hides the details. representation and storage of data.
DBMS provides a crash recovery File system doesn't have a crash mechanism, i.e.,
mechanism, i.e., DBMS protects the user if the system crashes while entering some data,
from the system failure. then the content of the file will lost.
DBMS provides a good protection It is very difficult to protect a file under the file
mechanism. system.
DBMS contains a wide variety of File system can't efficiently store and retrieve the
sophisticated techniques to store and data.
retrieve the data.
DBMS takes care of Concurrent access of In the File system, concurrent access has many
data using some form of locking. problems like redirecting the file while other
deleting some information or updating some
information.

Database System Concept and Architecture

Data Abstraction

Data abstraction is a technique to hide the implementation details of a database that


how a database is structured and how the data is stored physically. We need to hide
how the data is stored, managed and maintained. Abstraction levels are as follows:

1. Physical level
2. Logical level
3. View level
1.Physical level
The physical level is the bottom level of the abstraction levels.This level tells us how the data is
stored in the database

2.Logical level
The logical level is commonly called conceptual level point.The bottom level of abstraction is
physical level and the next one is the logical level point logical level is just above the physical
level point.This level tells us that what data is stored in the database. This level also tells us what
is the relationship that exists among all of the data.

3.View level
The bottom level of the abstraction is the physical level. Next higher level is the logical level.
The topmost level is view level.This level is specially designed for the end user. The end user
can only access the view level.

DATA MODELS:
 Data Model is the modeling of the data description, data semantics,
and consistencyconstraints of the data.
 It provides the conceptual tools for describing the design of a database
at each level ofdata abstraction.
 Therefore, there are following four data models used for
understanding the structureof the database:

Four Types of Data models are:

 Hierarchical model
 Network model
 Relational model
 ER model database

Hierarchical DBMS
In a Hierarchical database, model data is organized in a tree-like structure.
Data is StoredHierarchically (top down or bottom up) format. Data is
represented using a parent-child. . In Hierarchical DBMS parent may have
many children, but children have onlyone parent.

Network Model
The network database model allows each child to have multiple parents. It
helps you to address the need to model more complex relationships like as the
orders/parts many-to-manyrelationship. In this model, entities are organized
in a graph which can be accessed through several paths.

Relational model
Relational DBMS is the most widely used DBMS model because it is one of
the easiest. This model is based on normalizing data in the rows and columns
of the tables. Relational model stored in fixed structures and manipulated
using SQL.

Entity-Relationship Model
Entity-Relationship (ER) Model is based on the notion of real-world entities
and relationshipsamong them. While formulating real-world scenario into the
database model, the ER Model creates entity set, relationship set, general
attributes and constraints.
Instance and schema in DBMS

 Definition of schema: Design of a database is called the schema.


Schema is of threetypes: Physical schema, logical schema and view
schema.

 The design of a database at physical level is called physical


schema, how the datastored in blocks of storage is described at
this level.
 Design of database at logical level is called logical schema,
programmers and database administrators work at this level, at this
level data can be described as certaintypes of data records gets stored
in data structures, however the internal details such as implementation
of data structure is hidden at this level (available at physical level).
 Design of database at view level is called view schema. This
generally describes enduser interaction with database systems.
(OR)
Database schema refers to the format and layout of the database in which the data will be stored.
It is the one thing that remains the same throughout unless otherwise modified. It defines the
structure of what type of data and how it will be stored.
Example
A database schema for a person will have fields for name, email, phone and address as shown
below −
Person

Name Email Phone no

Definition of instance:
The data stored in database at a particular moment of time is called
instance of database. Database schema defines the variable declarations
in tables that belong to a particular database; the value of these variables
at a moment of time is called the instance of that database.
(OR)
Instance or extension or database state is a collection of information that stored in a database at a
particular moment is called an instance of the database. The Database instance refers to the
information stored in the database at a given point of time. Thus, it is a dynamic value which
keeps on changing.

Example
A database instance for the Person database can be (User1,emai.com,11345679,addr) So the
person construct will contain their individual entities in the attributes called as instance. This is
shown below −

Person

Name Email Phone no

BOB kksd@yasd.com 2343435

JANU werwr@sdas.in 5345464

PRIYA wefrwer@sdf.com 2342342

The-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 is also used to separate the user applications and physical
database.
o The three schema architecture contains three-levels. It breaks the database down into three
different categories.
The main objective of three level architecture is to enable multiple users to access the same
data with a personalized view while storing the underlying data only once. Thus it separates
the user's view from the physical structure of the database

1. Internal Level

o The internal level has an internal schema which describes the physical storage structure of
the database.
o The internal schema is also known as a physical schema.
o It uses the physical data model. It is used to define that how the data will be stored in a
block.
o The physical level is used to describe complex low-level data structures in detail.

2. Conceptual Level
o The conceptual schema describes the design of a database at the conceptual level.
Conceptual level is also known as logical level.
o The conceptual schema describes the structure of the whole database.
o The conceptual level describes what data are to be stored in the database and also describes
what relationship exists among those data.
o In the conceptual level, internal details such as an implementation of the data structure are
hidden.
o Programmers and database administrators work at this level.
3. External Level
o At the external level, a database contains several schemas that sometimes called as
subschema. The subschema is used to describe the different view of the database.
o An external schema is also known as view schema.
o Each view schema describes the database part that a particular user group is interested and
hides the remaining database from that user group.
o The view schema describes the end user interaction with database systems.

Data Independence and Database Languages & Interfaces


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.

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.

DBMS Languages

Database languages are used to read, update and store data in a database.
There are severalsuch languages that can be used for this purpose; one of
them is SQL (Structured Query Language).

 DDL – Data Definition Language:


(CREATE,DROP,ALTER,TRUNCATE,COMME
NT,RENAME)
 DML – Data Manipulation Language: (INSERT, UPDATE,DELETE)
 DCL – Data Control Language: (GRANT,REVOKE)
 TCL-Transaction Control Language: (COMMIT,ROLLBACK)

1 . DDL(Data Definition Language) : DDL or Data Definition Language actually


consists ofthe SQL commands that can be used to define the database schema. It simply
deals with descriptions of the database schema and is used to create and modify the
structure of databaseobjects in the database.

CREATE – it is used to create the database or its objects (like table, index,
function, views, store procedure and triggers).
There are two CREATE statements available in SQL:
 CREATE DATABASE
 CREATE TABLE
CREATE DATABASE
A Database is defined as a structured set of data. So, in SQL the very first step
to store thedata in a well structured manner is to create a database. The
CREATE
DATABASE statement is used to create a new
database in SQL.
Syntax:
CREATE DATABASE database_name;
Example:
SQL> CREATE DATABASE Employee;
In order to get the list of all the databases, you can use SHOW
DATABASES statement.

Example –
SQL> SHOW DATABASES;
CREATE TABLE:

The CREATE TABLE statement is used to create a table in SQL. A table comprises of rows and
columns. So while creating tables we have to provide all the information to SQL about the
names of the columns, type of data to be stored in columns, size of the data etc.

Syntax:

CREATE TABLE table_name(

column1 data_type(size),

column2 data_type(size),

column3 data_type(size)

....

);

Example Query:
CREATE TABLE Students(

ROLL_NO int(3),

NAME varchar(20),

SUBJECT varchar(20),

);

DROP:
DROP is used to delete a whole database or just a table.The DROP statement
destroys theobjects like an existing database, table, index, or view.
Syntax:
DROP object object_name;
Examples:
DROP TABLE table_name; (Name of the table to be deleted).
TRUNCATE
It is used to remove all records from a table, including all spaces.
Syntax:
TRUNCATE TABLE table_name;
DROP vs TRUNCATE
 Truncate is normally ultra-fast and its ideal for deleting data from a temporary
table.
 Truncate preserves the structure of the table for future use, unlike
drop table wherethe table is deleted with its full structure.
 Table or Database deletion using DROP statement cannot be rolled
back, so it must beused wisely.
2 .DML(Data Manipulation Language) : The SQL commands that deals with the manipulation
of data present in the database belong to DML or Data Manipulation Languageand this
includes most of the SQL statements.

SELECT Statement
select statement is used to fetch data from relational database. A relational database is organized
collection of data.
SELECT Syntax
One column:
Here column_name is the name of the column for which we need to fetch
data andtable_name is the name of the table in the database.
SELECT column_name FROM table_name;
More than one columns:
SELECT column_name_1, column_name_2, ... FROM table_name;
To fetch the entire table or all the fields in the table:
SELECT * FROM table_name;
Example:
SELECT EMP_NAME FROM EMPLOYEES;
To fetch the entire EMPLOYEES table:
SELECT * FROM EMPLOYEES;
Query to fetch the fields ROLL_NO, NAME, AGE from
the table Student:

SELECT ROLL_NO, NAME, AGE FROM Student;


INSERT INTO Statement
The INSERT INTO statement of SQL is used to insert a new row in a table.
There are two ways of using INSERT INTO statement for inserting rows:
Only values: First method is to specify only the value of data to be inserted
without thecolumn names.
INSERT INTO table_name VALUES (value1, value2, value3,…);

Column names and values both: In the second method we will specify both the
columnswhich we want to fill and their corresponding values as shown below:

INSERT INTO table_name (column1, column2, column3,..) VALUES ( value1,


value2, value3,..);
Example:
Method 1 (Inserting only values) :
INSERT INTO Student VALUES (‘5′,’HARSH’,’WEST
BENGAL’,’XXXXXXXXXX’,’19’);
Method 2 (Inserting values in only specified columns):
INSERT INTO Student (ROLL_NO, NAME, Age) VALUES (‘5′,’PRATIK’,’19’);
UPDATE Statement
The UPDATE statement in SQL is used to update the data of an existing table
in database. We can update single columns as well as multiple columns using
UPDATE statement as requirement.
DELETE Statement
The DELETE Statement in SQL is used to delete existing records from a table.
We can deletea single record or multiple records depending on the condition
we specify in the WHERE clause.

3. DCL(Data Control Language) : DCL includes commands such as GRANT and


REVOKE which mainly deals with the rights, permissions and other controls of the
database system. Examples of DCL commands:
GRANT-gives user’s access privileges to database.
REVOKE-withdraw user’s access privileges given by using the GRANT command.

4.TCL(transaction Control Language) : TCL commands deals with the transaction


within thedatabase.

Examples of TCL commands:


COMMIT– commits a Transaction.
ROLLBACK– rollbacks a transaction in case of any error occurs.

DBMS Architecture
There are three types of DBMS architecture:
1.Single tier architecture
2.Two tier architecture
3.Three tier architecture
1- Tier Architecture
 In this type of architecture, the database is readily available on the
client machine, anyrequest made by client doesn’t require a network
connection to perform the action on the database.
 Any changes done here will directly be done on the database itself. It
doesn't providea handy tool for end users.
 The 1-Tier architecture is used for development of the local
application, where programmers can directly communicate with
the database for the quick response.

2. Two tier architecture


 In two-tier architecture, the Database system is present at the server
machine and the DBMS application is present at the client machine,
these two machines are connectedwith each other through a reliable
network.
 Whenever client machine makes a request to access the database
present at server using a query language like sql, the server
perform the request on the database andreturns the result back to
the client.
 The application connection interface such as JDBC, ODBC
are used for the interaction between server and client.

3-Tier Architecture
 In three-tier architecture, another layer is present between the
client machine andserver machine.
 In this architecture, the client application doesn’t communicate
directly with thedatabase systems present at the server machine,
rather the client application communicates with server
application and server application internally communicates with
database system present at the server
E-R Model concepts:
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. These rows in the table denote a real-world entity
or relationship.
The table name and column names are helpful to interpret the meaning of values in
each row.The data are represented as a set of relations. In the relational model, data are
stored as tables. However, the physical storage of the data is independent of the way the
data are logically organized.

Relational Model Concepts


1.Attribute: Each column in a Table. Attributes are the properties which define arelation. e.g.,
Student_Rollno, NAME,etc.

2.Tables – In the Relational model the, relations are saved in the table format. It
is stored along with its entities. A table has two properties rows and columns.
Rowsrepresent records and columns represent attributes.

3.Tuple – It is nothing but a single row of a table, which contains a single record.

4.Relation Schema: A relation schema represents the name of the relation with
itsattributes.

5.Degree: The total number of attributes which in the relation is called the degree of
therelation.

6.Cardinality: Total number of rows present in the Table.


7.Column: The column represents the set of values for a specific attribute.
8.Relation instance – Relation instance is a finite set of tuples in the RDBMS system.
Relation instances never have duplicate tuples.

Keys in DBMS
KEYS in DBMS is an attribute or set of attributes which helps you to identify a

row(tuple) ina relation(table). They allow you to find the relation between two
tables. Keys help you uniquely identify a row in a table by a combination of
one or more columns in that table. Key is also helpful for finding unique record
or row from the table. Database key is also helpful for finding unique record
or row from the table.

Why we need a Key?

Here are some reasons for using sql key in the DBMS system.

 Keys help you to identify any row of data in a table. In a real-world


application, a table could contain thousands of records. Moreover, the
records could be duplicated. Keys ensure that you can uniquely
identify a table record despite these challenges.
 Allows you to establish a relationship between and identify the
relation betweentables
 Help you to enforce identity and integrity in the relationship.

Types of Keys in Database Management System


There are mainly seven different types of Keys in DBMS and each key has its different
functionality:

Super Key - A super key is a group of single or multiple keys which identifies rows in a table.
Super key is a set of an attribute which can uniquely identify a tuple. Super key is a superset of a
candidate key.
For example: In the above EMPLOYEE table, for(EMPLOEE_ID, EMPLOYEE_NAME) the
name of two employees can be the same, but their EMPLYEE_ID can't be the same. Hence, this
combination can also be a key.
The super key would be EMPLOYEE-ID, (EMPLOYEE_ID, EMPLOYEE-NAME), etc.

Primary Key - is a column or group of columns in a table that uniquely identify every row in that
table. It is the first key which is used to identify one and only one instance of an entity uniquely.
An entity can contain multiple keys as we saw in PERSON table. The key which is most suitable
from those lists become a primary key.
o In the EMPLOYEE table, ID can be primary key since it is unique for each employee. In the
EMPLOYEE table, we can even select License_Number and Passport_Number as primary key
since they are also unique.

o For each entity, selection of the primary key is based on requirement and developers.

Candidate Key - is a set of attributes that uniquely identify tuples in a table. Candidate Key is a
super key with no repeated attributes. A candidate key is an attribute or set of an attribute which
can uniquely identify a tuple.

o The remaining attributes except for primary key are considered as a candidate key. The candidate
keys are as strong as the primary key.

For example: In the EMPLOYEE table, id is best suited for the primary key. Rest of the attributes
like SSN, Passport_Number, and License_Number, etc. are considered as a candidate key
Foreign Key - is a column that creates a relationship between two tables. The purpose of Foreign
keys is to maintain data integrity and allow navigation betweentwo different instances of an entity.
Foreign keys are the column of the table which is used to point to the primary key of another table.

o In a company, every employee works in a specific department, and employee and department
are two different entities. So we can't store the information of the department in the employee
table. That's why we link these two tables through the primary key of one table.

o We add the primary key of the DEPARTMENT table, Department_Id as a new attribute in the
EMPLOYEE table.

o Now in the EMPLOYEE table, Department_Id is the foreign key, and both the tables are related.

E-R model Concepts


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 andeasy to design view of data.
o In ER modeling, the database structure is portrayed as a diagram
called an entity-relationship diagram.

Notations for E-R Model


For example, Suppose we design a school database. In this database, the student will
be anentity 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. Consider an organization as an example- manager, product, employee,
department etc. can betaken as an entity

a. Weak Entity

An entity that depends on another entity called a weak entity. The weak entity
doesn't containany key attribute of its own. The weak entity is represented by
double rectangle

2. Attribute

The attribute is used to describe the property of an entity. Eclipse is used to


represent anattribute.
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 aprimary 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.


Thecomposite 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
multivaluedattribute. 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 berepresented by a dashed ellipse.
For example, A person's age changes over time and can be derived from another
attributelike Date of birth.

3.Relationship
A relationship is used to describe the relation between entities. Diamond or rhombus
is usedto represent the relationship

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 asone to one relationship.

For example, A female can marry to one male, and a male can marry to one female.

b.One-to-many relationship
When only one instance of the entity on the left, and more than one instance of an
entity onthe 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 onlyspecific scientist.

c. Many-to-one relationship
When more than one instance of the entity on the left, and only one instance of an
entity onthe 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.

d. Many-to-many relationship
When more than one instance of the entity on the left, and more than one instance of
an entityon 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 the Constraints


Mapping Constraints are greatly functional in recognizing the relationships between the Entities
that involve more than one relationship for any given Entity. Mapping Constraints are also
known as the ‘Cardinality Ratio.’ This corresponds to the number of relationship occurrences an
entity can be involved in an Entity-Relationship Model.
Types of Mapping Constraints

 One to one (1:1)


 One to many (1:M)
 Many to one (M:1)
 Many to Many (M M)

1. One to one Cardinality

When one object from an entity is connected with a single object from another entity of the same
Entity-Relationship model, then the Mapping Constraint can be termed ‘One to One Cardinality.’
As the name suggests, it can have only one to one relationship. If there appears a need for involving
more than one Entity object in the mapping, then the other cardinality types can be used. Here each
entity object from the entity set contributes not more than once in the relationship.

The above example (Fig. 01) shows the entity Employee and the entity Salary Account, with the
relationship condition as salary. One employee working for any company can have only one Salary
account. This applies to all employees, without any exception. Hence this Entity-relationship
mapping falls under the one-to-one cardinality type.

2. One to many Cardinality

When one object from an entity is connected with more than one object from the same entity of
the same Entity-Relationship model, the Mapping Constraint can be termed ‘One to Many
Cardinality.’ As the name suggests, it can have only one to many relationships. If there appears to
be a need for involving more than one entity on the left side of the mapping or for only one entity
object on the right side, then the other cardinality types can be used. Here one entity object from
the left entity set contributes to more than one entity object in the right entity set as the mapping
relationship.
The above example (Fig. 02) shows the entity Employee and the entity Sales, with the relationship
condition as Job. An employee working for a company can make more than one sale. But not more
than one employee can make the same sale. This applies to all employees and sales, without any
exception. Hence this Entity-relationship mapping falls under the one-to-many cardinality types.

3. Many to one Cardinality

When many objects from an entity are connected with only one object from the other entity of the
same Entity-Relationship model, the Mapping Constraint can be termed ‘Many to one Cardinality.’
As the name suggests, it can have many to-one mapping relationships. If there appears to be a need
for involving only one entity on the left side of the mapping or for more than one entity object on
the right side, then the other cardinality types can be used. Here many entity objects from the left
entity set contribute to only one entity object in the right entity set as the mapping relationship.

The above example (Fig. 03) shows the entity Employee and the entity Sales, with the relationship
condition as Job. Many Employees working for a company can report to one Manager. But not
one employee can be reporting to more than one Manager. This applies to all employees, managers,
and reporting, without any exception. Hence this Entity-relationship mapping falls under the many
to one cardinality type.

4. Many to many Cardinality

When many objects from an entity are connected with more than one object from the other entity
of the same Entity-Relationship model, the Mapping Constraint can be termed ‘Many to Many
Cardinality.’ As the name suggests, it can have many, many mapping relationships. If there appears
a need for involving only one entity on the left side of the mapping or for only one entity object
on the right side of the mapping, then the other cardinality types can be used. Here more than one
entity object from the left entity set contributes to more than one entity object in the right entity
set as the mapping relationship.

The above example (Fig. 04) shows the entity Employee and the customer, with the relationship
condition as sales. Many Employees working for a company can be making sales to many
customers. There is no condition for one employee to make sales with only one customer or for
one customer to buy the sale from only one employee. This applies to all employees, sales, and
customers, without any exception. Hence this Entity-relationship mapping falls under the many to
many cardinality types.
Mapping the constraints
A database must conform to certain defined constraints of the contents.

Mapping Cardinalities
Mapping cardinalities is the number of entities to which another entity can be linked
through a relationship set.
There are four types of mapping cardinalities.
Let A and B be two entity sets.

1. a) One-to-one : An entity in A is associated with no more than one entity in B and an entity in B
is associated with no more than one entity in A.
b) One-to-many : An entity in A is associated with many entities in B and an entity in B is
associated with at most one entity in A.

c) Many-to-one : Many entities in A can be associated with at most one entity in B and an entity
in B can be associated with many entities in A.

d) Many-to-many : Many entities in A can be associated with many entities in B and many
entities in B can be associated with many entities in A.
Participation Constraints :
1. a) Total : The participation of an entity set E in a relationship R is considered ‘total’ if every
entity in E participates in R.

b) Partial : If only some entities in E participate in relationship R, then it is called ‘partial’.


Concept of Keys
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.

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

o It is the first key used to identify one and only one instance of an entity uniquely. An entity
can contain multiple keys, as we saw in the PERSON table. The key which is most suitable
from those lists becomes a primary key.
o In the EMPLOYEE table, ID can be the primary key since it is unique for each employee.
In the EMPLOYEE table, we can even select License_Number and Passport_Number as
primary keys since they are also unique.
o For each entity, the primary key selection is based on requirements and developers.
2.Candidate key

o A candidate key is an attribute or set of attributes that can uniquely identify a tuple.
o Except for the primary key, the remaining attributes are considered a candidate key. The
candidate keys are as strong as the primary key.

For example: In the EMPLOYEE table, id is best suited for the primary key. The rest of the
attributes, like SSN, Passport_Number, License_Number, etc., are considered a candidate key.

3. Super Key

Super key is an attribute set that can uniquely identify a tuple. A super key is a superset of a
candidate key. In the above EMPLOYEE table, for(EMPLOEE_ID, EMPLOYEE_NAME), the
name of two employees can be the same, but their EMPLYEE_ID can't be the same. Hence, this
combination can also be a key. The super key would be EMPLOYEE-ID (EMPLOYEE_ID,
EMPLOYEE-NAME), etc
4.Foreign Key

o Foreign keys are the column of the table used to point to the primary key of another table.
o Every employee works in a specific department in a company, and employee and
department are two different entities. So we can't store the department's information in the
employee table. That's why we link these two tables through the primary key of one table.
o We add the primary key of the DEPARTMENT table, Department_Id, as a new attribute
in the EMPLOYEE table.
o In the EMPLOYEE table, Department_Id is the foreign key, and both the tables are related

Generalization, Specialization and Aggregation in ER Model

Generalization –
Generalization is the process of extracting common properties from a set of entities and create a
generalized entity from it. It is a bottom-up approach in which two or more entities can be
generalized to a higher level entity if they have some attributes in common. For Example,
STUDENT and FACULTY can be generalized to a higher level entity called PERSON as shown
in Figure 1. In this case, common attributes like P_NAME, P_ADD become part of higher entity
(PERSON) and specialized attributes like S_FEE become part of specialized entity
(STUDENT).
Specialization –
In specialization, an entity is divided into sub-entities based on their characteristics. It is a top-
down approach where higher level entity is specialized into two or more lower level entities. For
Example, EMPLOYEE entity in an Employee management system can be specialized into
DEVELOPER, TESTER etc. as shown in Figure 2. In this case, common attributes like
E_NAME, E_SAL etc. become part of higher entity (EMPLOYEE) and specialized attributes
like TES_TYPE become part of specialized entity (TESTER).

Aggregation –
An ER diagram is not capable of representing relationship between an entity and a relationship
which may be required in some scenarios. In those cases, a relationship with its corresponding
entities is aggregated into a higher level entity. Aggregation is an abstraction through which we
can represent relationships as higher level entity sets.

For Example, Employee working for a project may require some machinery. So, REQUIRE
relationship is needed between relationship WORKS_FOR and entity MACHINERY. Using
aggregation, WORKS_FOR relationship with its entities EMPLOYEE and PROJECT is
aggregated into single entity and relationship REQUIRE is created between aggregated entity
and MACHINERY.
Reduction of ER diagram to Table

The database can be represented using the notations, and these notations can be reduced to a
collection of tables.

In the database, every entity set or relationship set can be represented in tabular form.

There are some points for converting the ER diagram to the table:

 Entity type becomes a table.


In the given ER diagram, LECTURE, STUDENT, SUBJECT and COURSE forms individual
tables.

 All single-valued attribute becomes a column for the table.


In the STUDENT entity, STUDENT_NAME and STUDENT_ID form the column of STUDENT
table. Similarly, COURSE_NAME and COURSE_ID form the column of COURSE table and so
on.

 A key attribute of the entity type represented by the primary key.


In the given ER diagram, COURSE_ID, STUDENT_ID, SUBJECT_ID, and LECTURE_ID are
the key attribute of the entity.

 The multivalued attribute is represented by a separate table.


In the student table, a hobby is a multivalued attribute. So it is not possible to represent multiple
values in a single column of STUDENT table. Hence we create a table STUD_HOBBY with
column name STUDENT_ID and HOBBY. Using both the column, we create a composite key.

 Composite attribute represented by components.


In the given ER diagram, student address is a composite attribute. It contains CITY, PIN, DOOR#,
STREET, and STATE. In the STUDENT table, these attributes can merge as an individual column.

 Derived attributes are not considered in the table.


In the STUDENT table, Age is the derived attribute. It can be calculated at any point of time by
calculating the difference between current date and Date of Birth.

Using these rules, you can convert the ER diagram to tables and columns and assign the mapping
between the tables. Table structure for the given ER diagram is as below:
Overall DBMS Architecture

On the basis of how they use the database we can divide them into three categories:

 DBA: Database administrator have full control on database. They may be a group
of persons or a single person. They use Data Definition Language to pass on
schemas and mapping constraints on database, which further passed to DDL
processor.
 Users: These are end users who actually use database for their own purposes. They
pass queries with the help of interface system provided. These queries further
passed on to the Queries processor.
 Programmers: These are the persons who actually creates database and manages
it technically. They use Data Manipulation Language statements to pass on
application programs to database, which further goes to DML processor.
The Query Processor

Processors: These processors execute the different types of queries passed to them. As per the
type of queries and statements passed on, we have three types of processors as per given below:

 DDL Processor: These compile the data definition language statements passed by
DBA and also convert the system generated output to the DDL statements for
understanding of DBA. These are further divided in two segments as per given
below:
1. DDL Statement: Identify the DDL statements and convert them into
the low-level language understandable to the data dictionary for further
execution.
2. DDL Compiler: Receive the data from DDL statements and compile
them so that they can be executed by further processes.
 Queries Processor: These compile the queries passed by end users and also
convert the system generated output to the natural language for understanding of
End users. These are further divided in two segments as per given below:
1. Interactive Query: identify the Queries and convert them into the low-
level language understandable to the data dictionary for further
execution.
 Query Compiler: receive the data from Interactive Query and compile them so
that they can be executed by further processes.
DML Processor: These compile the queries passed by application programmers
and also convert the system generated output to the DML statements for
understanding of Programmers. These are further divided in two segments as per
given below:
1. DML Statement: identify the DML statements and convert them into
the low level language understandable to the data dictionary for further
execution.
2. DML Compiler: It compiled or translate the DML statements received
by End users or programmers into a query language. This query
language is consisting of low-level language so that query evaluation
engine can understand it, execute it and performed the required or
desired operation.
 Query Evaluation Engine: This is the actual processor which executes all the
translated or interpreted low level commands or queries received from above
mentioned processors.
 Embedded DML pre-compiler: It received the application embedded DML
statements and converts them to normal procedure calls in the host language used.
Also, the pre-compiler interacts with DML compiler to generate the appropriate
code to remove conflicts.
 DDL Interpreter: It interprets DDL statements and saves the data definitions in
the data dictionary for further records.
 StorData Dictionary: It stored meta data, means data about data. It helps the
overall system to identify the data type received or generated. It’s also helps to
separate the schemas data language, interactive queries passed by end user and the
DML statements or application programs for better understanding of system and
smooth functioning.
 Authorization and Integrity Manager: As name implies its checks and allot the
authority of the user and manages the integrity constraints applied on database.
 Command Processor: Execute the commands received from the compilers.
 Query Optimizer: This optimize the queries so that these queries can be processed
in the minimum resource utilization.
 Transaction Manager: It manages the over all transactions performed in the
complete system for smooth and conflict free experience. Also, it ensures that the
database should be remain in consistent state because each and every transaction
affects the database.
 Scheduler: As name implies it schedules all the tasks in the system including
queries execution and transaction management.
 File Manager: It is responsible for allocation of space on disk storage and also
manages data structures and techniques used in representation of the information
stored on the disk.
 Buffer Manager: This manages and controls that how the required data maybe
fetched from storage and transferred to the main memory. Also manages the reverse
operation as well.
 Recovery Manager: It is like backup and restore option. All the operations and
transactions and all the changes made are going through this section so that it can
keep track and record of all these activities. So that whenever required it can
provide the backup or roll back the operations.
 Physical Database: This is actual physical storage where all the low level or real
data is stored. This can only save the data and transfer it when ordered.
Disk Storage

This manages the overall storage available. This can be further divided into these below sections:

 Data Files: It is actually the stored data. A data file is a storage block or bucket in
which data can be stored. Data files have variable sizes.
 Data Dictionary: It stores the data about data. Means what data is stored where at
which time and how to reach there.
 Indices: This works as a up to date index of all data items. It helps to fast access to
all these data items.
 Statical Data: As name implies it stores the statical information about any data
present in database.

You might also like