DBMS Unit-I

Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 172

Noida Institute of Engineering and Technology, Greater Noida

Introduction

Unit: 1

DBMS
ACSAI0402 Shabnam Firdaus
Assistant Professor
Course Details (AI)
(B Tech IVth Sem)

Shabnam Firdaus ACSAI-0402 -DBMS Unit-1


1
05/12/2023
Brief Introduction of Faculty member

Name: Shabnam Firdaus


Qualification: B.Tech(IT), M.Tech (IT)
Area of Research: Machine Learning, Artificial
Intelligence
Contact Details:
Email: [email protected]

05/12/2023 Shabnam Firdaus ACSAI-0402 -DBMS Unit-1 2


Evaluation Scheme

05/12/2023 Shabnam Firdaus ACSAI-0402 -DBMS Unit-1 3


Subject Syllabus

05/12/2023 Shabnam Firdaus ACSAI-0402 -DBMS Unit-1 4


Subject Syllabus

05/12/2023 Shabnam Firdaus ACSAI-0402 -DBMS Unit-1 5


Branch wise Applications

1.AI - Apache Cassandra is an open-source and highly scalable NoSQL database


management system that is designed to manage massive amounts of data in a
faster manner. This popular database is being used by GitHub, Netflix, Instagram,
Reddit, among others.

2. IoT - IoT devices' primary purpose is often to collect and/or generate data and
share it for some higher purpose such as analytics, machine learning and artificial
intelligence. Consequently, IoT DBMSs need to manage not just data at rest, but
also data in transit.

3. CS – There are various application of dbms in different fields like Railway


Reservation System, Library Management System, Banking, Universities and
colleges, Credit card transactions etc

05/12/2023 Shabnam Firdaus ACSAI-0402 -DBMS Unit-1 6


Course Objective

• The objective of course is to present an introduction to database


management systems, with an emphasis on how to organize,
maintain and retrieve-efficiently, and effectively –information in
relational and non-relational Database.
• List and explain the fundamental concepts of a relational database
system
• Knowledge of DBMS, both in terms of use and
implementation/design.
• Experience with SQL and Manipulate a database using SQL
• Increased proficiency with the programming language C++.
• Experience working as part of team v Experience with analysis and
design of (DB) software
• Assess the quality and ease of use of data modeling and
diagramming tools.
Shabnam Firdaus ACSAI-0402 -DBMS Unit-1
05/12/2023 7
Course Outcomes (COs)

05/12/2023 Shabnam Firdaus ACSAI-0402 -DBMS Unit-1 8


Program Outcomes (POs)

Engineering Graduates will be able to:


1. Engineering knowledge: Apply the knowledge of mathematics, science,
engineering fundamentals, and an engineering specialization to the solution of
complex engineering problems.

2. Problem analysis: Identify, formulate, review research literature, and analyze


complex engineering problems reaching substantiated conclusions using first
principles of mathematics, natural sciences, and engineering sciences.

3. Design/development of solutions: Design solutions for complex engineering


problems and design system components or processes that meet the specified
needs with appropriate consideration for the public health and safety, and the
cultural, societal, and environmental considerations.

4. Conduct investigations of complex problems: Use research-based knowledge


and research methods including design of experiments, analysis and interpretation
of data, and synthesis of the information to provide valid conclusions.

05/12/2023 Shabnam Firdaus ACSAI-0402 -DBMS Unit-1 9


Program Outcomes (POs)

Contd..

5. Modern tool usage: Create, select, and apply appropriate techniques,


resources, and modern engineering and IT tools including prediction and
modeling to complex engineering activities with an understanding of the
limitations.
6. The engineer and society: Apply reasoning informed by the contextual
knowledge to assess societal, health, safety, legal and cultural issues and
the consequent responsibilities relevant to the professional engineering
practice.
7. Environment and sustainability: Understand the impact of the
professional engineering solutions in societal and environmental contexts,
and demonstrate the knowledge of, and need for sustainable development.
8. Ethics: Apply ethical principles and commit to professional ethics and
responsibilities and norms of the engineering practice.

05/12/2023 Shabnam Firdaus ACSAI-0402 -DBMS Unit-1 10


Program Outcomes (POs)

Contd..

9. Individual and team work: Function effectively as an individual, and as a


member or leader in diverse teams, and in multidisciplinary settings.
10. Communication: Communicate effectively on complex engineering activities
with the engineering community and with society at large, such as, being able to
comprehend and write effective reports and design documentation, make
effective presentations, and give and receive clear instructions.
11. Project management and finance: Demonstrate knowledge and
understanding of the engineering and management principles and apply these
to one’s own work, as a member and leader in a team, to manage projects and
in multidisciplinary environments.
12. Life-long learning: Recognize the need for, and have the preparation and
ability to engage in independent and life-long learning in the broadest context of
technological change.

05/12/2023 Shabnam Firdaus ACSAI-0402 -DBMS Unit-1 11


COs and POs Mapping

PO1 PO2 PO3 PO4 PO5 PO6 PO7 PO8 PO9 PO10 PO11 PO12

ASCAI0402.1
2 2 3 3 3 2 3 2 2 2 2 3

ACSAI0402.2
3 3 3 2 2 2 2 2 2 2 2 3

ACSAI0402.3
2 3 3 3 3 2 2 2 2 2 2 2

ACSAI0402.4
2 3 2 2 2 2 2 2 2 3 2 2

ACSAI0402.5
2 3 2 2 2 3 2 2 3 2 2 2

AVG
2.20 2.80 2.60 2.40 2.40 2.20 2.20 2.00 2.20 2.20 2.00 2.40

05/12/2023 Shabnam Firdaus ACSAI-0402 -DBMS Unit-1 12


Program Specific Outcomes (PSOs)

On successful completion of graduation degree the Engineering graduates


will be able to:

PSO1: The ability to identify, analyze real world problems and design their ethical
solutions using artificial intelligence, robotics, virtual/augmented reality, data
analytics, block chain technology, and cloud computing.

PSO2:The ability to design and develop the hardware sensor devices and related
interfacing software systems for solving complex engineering problems.

PSO3:The ability to understand inter disciplinary computing techniques and to


apply them in the design of advanced computing.

PSO4: The ability to conduct investigation of complex problem with the help of
technical, managerial, leadership qualities, and moder engineering tools provided
by industry sponsored laboratories.

05/12/2023 Shabnam Firdaus ACSAI-0402 -DBMS Unit-1 13


COs and PSOs Mapping

Program Specific Outcomes

PSO1 PSO2 PSO3 PSO4

ACSAI0402.1
3 1 3 1
ACSAI0402.2
3 1 3 1
ACSAI0402.3
3 1 3 1
ACSAI0402.4
3 1 3 1
ACSAI0402.5
3 1 3 1
AVG
3.00 1.00 3.00 1.00

05/12/2023 Shabnam Firdaus ACSAI-0402 -DBMS Unit-1 14


Program Educational Objectives (PEOs)

PEO1: To have an excellent scientific and engineering breadth so as to comprehend,


analyze, design and provide sustainable solutions for real-life problems using state-of-
the-art technologies.

PEO2:To have a successful career in industries, to pursue higher studies or to support


entrepreneurial endeavors and to face global challenges.

PEO3:To have an effective communication skills, professional attitude, ethical values


and a desire to learn specific knowledge in emerging trends, technologies for
research, innovation and product development and contribution to society.

PEO4: To have life-long learning for up-skilling and re-skilling for successful
professional career as engineer, scientist, entrepreneur and bureaucrat for betterment
of society

05/12/2023 Shabnam Firdaus ACSAI-0402 -DBMS Unit-1 15


COs and PSOs Mapping

Program Specific Outcomes

PSO1 PSO2 PSO3 PSO4

ACSAI0402.1
3 1 3 1
ACSAI0402.2
3 1 3 1
ACSAI0402.3
3 1 3 1
ACSAI0402.4
3 1 3 1
ACSAI0402.5
3 1 3 1
AVG
3.00 1.00 3.00 1.00

05/12/2023 Shabnam Firdaus ACSAI-0402 -DBMS Unit-1 16


Result Analysis

05/12/2023 Shabnam Firdaus ACSAI-0402 -DBMS Unit-1 17


Question Paper Template

05/12/2023 Shabnam Firdaus ACSAI-0402 -DBMS Unit-1 18


Question Paper Template
    SECTION – A   CO
         
1.   Attempt all parts- [10×1=10]  

  1-a. Question- (1)  


  1-b. Question- (1)  
  1-c. Question- (1)  
  1-d. Question- (1)  
  1-e. Question- (1)  
  1-f. Question- (1)  
  1-g. Question- (1)  
  1-h. Question- (1)  
  1-i. Question- (1)  
  1-j. Question- (1)  
         
2. Attempt all parts- [5×2=10] CO
       
  2-a. Question- (2)  
  2-b. Question- (2)  
  2-c. Question- (2)  
  2-d. Question- (2)  
  2-e. Question- (2)  
       
       

 
SECTION – B   CO
     
3. Answer any five of the following- [5×6=30]  
3-a.  Question- (6)  
3-b.  Question- (6)  
3-c.  Question- (6)  
3-d.  Question- (6)  
3-e.  Question- (6)  
3-f.   Question- (6)  
3-g.  Question- (6)  
SECTION – C   CO
     
4 Answer any one of the following- [5×10=50]  

  4-a. Question- (10)  


         
  4-b. Question- (10)  
5. Answer any one of the following-    
  5-a. Question- (10)  
         
  5-b. Question- (10)  
6. Answer any one of the following-    
  6-a. Question- (10)  
         
  6-b. Question- (10)  
7. Answer any one of the following-    
  7-a. Question- (10)  
         
  7-b. Question- (10)  
         
8. Answer any one of the following-    
  8-a. Question- (10)  
         
  8-b. Question- (10)  

05/12/2023 Shabnam Firdaus ACSAI-0402 -DBMS Unit-1 19


Prerequisite and Recap

• There is No prerequisite for learning DBMS from scratch


although having basic knowledge of discrete mathematics and
data structure is added advantage.
• Having knowledge of basic mathematics like - SUM,
DIFFERENCE, AVERAGE, MEAN, MEDIAN, MODE, etc will
definitely be a plus point.
• Having knowledge on Set Theory will help.
• The proper understanding of data structures (B and B+ trees)
will help you to understand the DBMS quickly.

05/12/2023 Shabnam Firdaus ACSAI-0402 -DBMS Unit-1 20


Brief Introduction about the Subject with videos

1. A database management system (DBMS) refers to the technology for


creating and managing databases. DBMS is a software tool to organize
(create, retrieve, update, and manage) data in a database.
2. The main aim of a DBMS is to supply a way to store up and retrieve
database information that is both convenient and efficient. By data,
we mean known facts that can be recorded and that have embedded
meaning.

(15) 22 - DBMS - I – YouTube


(15) Lec
1: Introduction to DBMS | Database Management System – YouTube
(15) Introduction to SQL | DDL, DML, DQL, DCL, TCL Commands in SQL - Yo
uTube
(15) NoSQL Tutorial for Beginners | Introduction to NoSQL Databases | No
SQL Databases Tutorial – YouTube

05/12/2023 Shabnam Firdaus ACSAI-0402 -DBMS Unit-1 21


Content – Unit 1

• Introduction: An overview of database management system,


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.
• 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.

05/12/2023 Shabnam Firdaus ACSAI-0402 -DBMS Unit-1 22


Unit Objective

1. The main objectives of database management system are data


availability, data integrity, data security, and data independence.

2. DDL stands for Data Definition Language. DML stands for Data
Manipulation Language. DDL statements are used to create
database, schema, constraints, users, tables etc. DML statement is
used to insert, update or delete the records.

3.  ER diagrams are used to analyze existing databases to find and


resolve problems in logic or deployment. Drawing the diagram
should reveal where it's going wrong. Business information systems:
The diagrams are used to design or analyze relational databases
used in business processes.

05/12/2023 Shabnam Firdaus ACSAI-0402 -DBMS Unit-1 23


Topic mapping with CO

Topic CO
Database system Vs File system CO1

Database system concepts, CO1


architecture and structures CO1
data model CO1
schema and instances
Data independence and Database CO1
language and Interfaces
Data Modeling using the Entity CO1
Relationship Model
ER model concepts CO1
notation for ER diagram CO1
mapping constraints CO1
keys CO1
Concepts of Super Key Shabnam Firdaus ACSAI-0402 -DBMS CO1
Unit-1

05/12/2023 24
Topic mapping with CO

Topic CO
Candidate key CO1
Primary key CO1
Generalization, Aggregation CO1
Reduction CO1
of an ER diagrams to tables
Extended ER model CO1

Relationship of higher degree. CO1

Shabnam Firdaus ACSAI-0402 -DBMS Unit-1

05/12/2023 25
Lecture 1
• Why we use DBMS
• File vs DBMS
• Purpose of Database system

Shabnam Firdaus ACSAI-0402 -DBMS Unit-1

05/12/2023 26
Topic – DBMS Objective

The main objectives of database


management system are data availability,
data integrity, data security, and data
independence.

05/12/2023 Shabnam Firdaus ACSAI-0402 -DBMS Unit-1 27


What is a DBMS? (CO1)

• A very large, integrated collection of related data.


• Models real-world enterprise.
– Entities (e.g., students, courses)
– Relationships (e.g., Madonna is taking CS564)
• A Database Management System (DBMS) is a
software package designed to define,construct and
manipulate database.
• Database + Database Management System=
Database System.

05/12/2023 Shabnam Firdaus ACSAI-0402 -DBMS Unit-1 28


Why Use a DBMS?

• Data independence and efficient access.


• Reduced application development time.
• Data integrity and security.
• Uniform data administration.
• Concurrent access, recovery from crashes.

05/12/2023 Shabnam Firdaus ACSAI-0402 -DBMS Unit-1 29


Why Study Databases?

Shift from computation to information


at the “low end”: scramble to webspace (a mess!)
at the “high end”: scientific applications
Datasets increasing in diversity and volume.
Digital libraries, interactive video, Human Genome
project, EOS project
... need for DBMS exploding
DBMS encompasses most of CS
OS, languages, theory, AI, multimedia, logic

05/12/2023 Shabnam Firdaus ACSAI-0402 -DBMS Unit-1 30


Files vs. DBMS

• The file system is basically a way of arranging the files


in a storage medium like a hard disk.
• The file system organizes the files and helps in the
retrieval of files when they are required.
• File systems consist of different files which are
grouped into directories.
• The directories further contain other folders and files.
The file system performs basic operations like
management, file naming, giving access rules, etc. 
• Example: NTFS(New Technology File System),
EXT(Extended File System).
05/12/2023 Shabnam Firdaus ACSAI-0402 -DBMS Unit-1 31
Files vs. DBMS

Basis File System DBMS

The file system is software that manages DBMS is software for managing the
Structure and organizes the files in a storage
database.
medium within a computer.

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


Data Redundancy system. data.

It doesn’t provide backup and recovery of It provides backup and recovery of


Backup and Recovery data if it is lost. data even if it is lost.

There is no efficient query processing in Efficient query processing is there in


Query processing the file system. DBMS.

There is more data consistency


There is less data consistency in the file
Consistency system.
because of the process of
normalization.

It has more complexity in handling


Complexity It is less complex as compared to DBMS.
as compared to the file system.

05/12/2023 Shabnam Firdaus ACSAI-0402 -DBMS Unit-1 32


Files vs. DBMS

File systems provide less security in DBMS has more security


Security Constraints comparison to DBMS. mechanisms as compared to file
systems.
It has a comparatively higher cost
Cost It is less expensive than DBMS.
than a file system.
In DBMS data independence
Data Independence There is no data independence. exists.
Only one user can access data at a Multiple users can access data at
User Access time. a time.
The user has to write procedures The user not required to write
Meaning for managing databases procedures.
Data is distributed in many files. Due to centralized nature sharing
Sharing  So, not easy to share data is easy
It give details of storage and It hides the internal details of
Data Abstraction representation of data Database
Integrity Constraints are difficult to Integrity constraints are easy to
Integrity Constraints implement implement
Example Cobol, C++ Oracle, SQL Server

05/12/2023 Shabnam Firdaus ACSAI-0402 -DBMS Unit-1 33


Purpose of Database Systems

In the early days, database applications were built directly on top of
file systems
Drawbacks of using file systems to store data:
Data redundancy and inconsistency
Multiple file formats, duplication of information in different
files
Difficulty in accessing data
Need to write a new program to carry out each new task
Data isolation — multiple files and formats
Integrity problems
Integrity constraints (e.g. account balance > 0) become
“buried” in program code rather than being stated explicitly
Hard to add new constraints or change existing ones

05/12/2023 Shabnam Firdaus ACSAI-0402 -DBMS Unit-1 34


Purpose of Database Systems (Cont.)
• Drawbacks of using file systems (cont.)
– Atomicity of updates
• Failures may leave database in an inconsistent state with partial
updates carried out
• Example: Transfer of funds from one account to another should
either complete or not happen at all
– Concurrent access by multiple users
• Concurrent access needed for performance
• Uncontrolled concurrent accesses can lead to inconsistencies
– Example: Two people reading a balance and updating it at the
same time
– Security problems
• Hard to provide user access to some, but not all, data
• Database systems offer solutions to all the above problems

05/12/2023 Shabnam Firdaus ACSAI-0402 -DBMS Unit-1 35


Summary

• DBMS used to maintain, query large datasets.


• Benefits include recovery from system crashes,
concurrent access, quick application development,
data integrity and security.
• Levels of abstraction give data independence.
• A DBMS typically has a layered architecture.
• DBAs hold responsible jobs and are well-paid!
• DBMS R&D is one of the broadest, most exciting
areas in CS.

05/12/2023 Shabnam Firdaus ACSAI-0402 -DBMS Unit-1 36


Short Quiz

1. Which of the following is a NoSQL Database Type?


a) SQL
b) Database Management System
c) Database Management Service
d) Data Backup Management System

2. What is a database?
a) Organized collection of information that cannot be
accessed, updated, and managed
b) Collection of data or information without organizing
c) Organized collection of data or information that can be
accessed, updated, and managed
d) Organized collection of data that cannot be updated

05/12/2023 Shabnam Firdaus ACSAI-0402 -DBMS Unit-1 37


Lecture 2
• Data Models
• Database Arcitecture
• Schema and instances
• Levels of Abstraction
• Data Independence
Shabnam Firdaus ACSAI-0402 -DBMS Unit-1

05/12/2023 38
Topic – Data models Objective

1. Data Model gives us an idea that how the final


system will look like after its complete
implementation.

2. It defines the data elements and the


relationships between the data elements.

3. Data Models are used to show how data is


stored, connected, accessed and updated in the
database management system.

05/12/2023 Shabnam Firdaus ACSAI-0402 -DBMS Unit-1 39


Data Models
• Data models define how the logical structure of a database is modeled.
• Data models define how data is connected to each other and how they are
processed and stored inside the system.

05/12/2023 Shabnam Firdaus ACSAI-0402 -DBMS Unit-1 40


Data Models

1) Relational Data Model: This type of model designs the data in the form
of rows and columns within a table. Thus, a relational model uses tables for
representing data and in-between relationships. Tables are also called
relations.

2) Entity-Relationship Data Model: An ER model is the logical


representation of data as objects and relationships among them. These objects
are known as entities, and relationship is an association among these entities. 

3) Object-based Data Model: An extension of the ER model with notions of


functions, encapsulation, and object identity, as well. This model supports a
rich type system that includes structured and collection types. Both the data
and the relationship are contained in a single structure that is known
as an object in this model. We can now store audio, video, pictures,
and other types of data in databases, which was previously impossible
with the relational approach

05/12/2023 Shabnam Firdaus ACSAI-0402 -DBMS Unit-1 41


Data Models

4) Semistructured Data Model: This type of data model is different


from the other three data models (explained above). The
semistructured data model allows the data specifications at places
where the individual data items of the same type may have
different attributes sets. 

5)Hierarchical Model: This concept uses a hierarchical tree


structure to organise the data. The hierarchy begins at the root,
which contains root data, and then grows into a tree as child
nodes are added to the parent node. 

6) Network Model : The main difference between this model and


the hierarchical model is that any record can have several parents
in the network model. It uses a graph instead of a hierarchical tree.
05/12/2023 Shabnam Firdaus ACSAI-0402 -DBMS Unit-1 42
DBMS Architecture

• Two-tier architecture: 
The two-tier architecture is similar to a basic client-server model.
• The application at the client end directly communicates with the
database at the server side using API.
• (Application Programming Interface (API) is a software
interface that allows two applications to interact with each
other without any user intervention. API is a collection of
software functions and procedures. In simple terms, API means
a software code that can be accessed or executed. API is defined
as a code that helps two different software’s to communicate
and exchange data with each other.)

05/12/2023 Shabnam Firdaus ACSAI-0402 -DBMS Unit-1 43


DBMS Architecture

• The server side is responsible for providing query


processing and transaction management functionalities.
• On the client side, the user interfaces and application
programs are run. The application on the client side
establishes a connection with the server side in order to
communicate with the DBMS. 
An advantage of this type is that maintenance and
understanding are easier, and compatible with existing
systems. However, this model gives poor performance
when there are a large number of users. 

05/12/2023 Shabnam Firdaus ACSAI-0402 -DBMS Unit-1 44


DBMS Architecture

05/12/2023 Shabnam Firdaus ACSAI-0402 -DBMS Unit-1 45


DBMS Architecture

• The main disadvantages of Two-Tier DBMS


Architecture are:
• Scalability - As the number of clients
increases, the load on the server increases.
Thereby declining the performance of the
DBMS and, in turn, the client-side application.
• Security - The Direct connection between the
client and server systems makes this
architecture vulnerable to attacks.

05/12/2023 Shabnam Firdaus ACSAI-0402 -DBMS Unit-1 46


DBMS Architecture

• Three Tier architecture: 


In this type, there is another layer between the client and
the server.
• The client does not directly communicate with the server.
Instead, it interacts with an application server which further
communicates with the database system and then the query
processing and transaction management takes place.
• This intermediate layer acts as a medium for the exchange
of partially processed data between server and client.
• This type of architecture is used in the case of large web
applications. 

05/12/2023 Shabnam Firdaus ACSAI-0402 -DBMS Unit-1 47


             DBMS Architecture

A 3-tier architecture has the following layers:


1. Presentation layer (your PC, Tablet, Mobile, etc.)
2. Application layer (server)
3. Database Server

05/12/2023 Shabnam Firdaus ACSAI-0402 -DBMS Unit-1 48


             DBMS Architecture

• The main advantages of Three Tier DBMS Architecture


are:
• Scalability - Since the database server isn't aware of any
users beyond the application layer and the application
layer implements load balancing, there can be as many
clients as you want.
• Data Integrity - Data corruption and bad requests can be
avoided because of the checks performed in the
application layer on each client reques.
• Security - The removal of the direct connection between
the client and server systems via abstraction reduces
unauthorized access to the database.
05/12/2023 Shabnam Firdaus ACSAI-0402 -DBMS Unit-1 49
Schemas and Instances

• Similar to types and variables in programming languages


• Schema – the logical structure of the database
– Example: The database consists of information about a
set of customers and accounts and the relationship
between them
– Analogous to type information of a variable in a program

• Instance – the actual content of the database at a


particular point in time
– Analogous to the value of a variable

05/12/2023 Shabnam Firdaus ACSAI-0402 -DBMS Unit-1 50


Schemas and Instances

• What is a Schema?

• It refers to an overall description that we get for any


given database. In simpler words, schema refers to the
basic structure of how one needs to store data in any
database. There are basically two types of Schema:
Physical Schema and Logical Schema.
• Physical Schema – This schema describes the DB
designed at a physical level.
• Logical Schema – This schema describes the DB
designed at a logical level.

05/12/2023 Shabnam Firdaus ACSAI-0402 -DBMS Unit-1 51


Schemas and Instances

• Example: Let’s say a table teacher in our


database name school, the teacher table
require the name, dob, doj in their table so we
design a structure as 

05/12/2023 Shabnam Firdaus ACSAI-0402 -DBMS Unit-1 52


Schemas and Instances

•Physical Database Schema − This schema pertains to the actual storage of data and
its form of storage like files, indices, etc. It defines how the data will be stored in a
secondary storage.
•Logical Database Schema − This schema defines all the logical constraints that
need to be applied on the data stored. It defines tables, views, and integrity
constraints.

05/12/2023 Shabnam Firdaus ACSAI-0402 -DBMS Unit-1 53


Schemas and Instances

• What are Instances?


• These refer to a collection of all the information and data
stored at any given moment.
• One can easily change these instances using certain
operations, such as deletion and addition of data and
information.
• Example : Let’s say a table teacher in our database whose
name is School, suppose the table has 50 records so the
instance of the database has 50 records for now and
tomorrow we are going to add another fifty records so
tomorrow the instance have total 100 records. This is
called an instance. 

05/12/2023 Shabnam Firdaus ACSAI-0402 -DBMS Unit-1 54


Schemas and Instances

Parameters Schema in DBMS Instance in DBMS


Meaning Schema refers to the Instance basically refers to
overall description of any a collection of data and
given database. information that the
database stores at any
particular moment.
Alterations The schema remains the One can change the
same for the entire instances of data and
database as a whole. information in a database
using updation, deletion,
and addition.
Frequency of Change It does not change very It changes very frequently.
frequently.
Uses We use Schema for We use Instance for
defining the basic referring to a set of
structure of any given information at any given
database. It defines how instance/ time.
the available needs to get
stored.

05/12/2023 Shabnam Firdaus ACSAI-0402 -DBMS Unit-1 55


Levels of Abstraction

• Physical Schema/Level: describes how a record (e.g., customer) is


stored.
• Logical Schema/Level: describes data stored in database, and the
relationships among the data.
type customer = record
customer_id : string;
customer_name : string;
customer_street : string;
customer_city : string;
end;
• External Schema/Level: application programs hide details of data
types. Views can also hide information (such as an employee’s
salary) for security purposes.

05/12/2023 Shabnam Firdaus ACSAI-0402 -DBMS Unit-1 56


Data Abstraction 

• Data Abstraction is a process of hiding unwanted or


irrelevant details from the end user. It provides a
different view and helps in achieving data
independence which is used to enhance the security
of data.
• The database systems consist of complicated data
structures and relations. For users to access the data
easily, these complications are kept hidden, and only
the relevant part of the database is made accessible to
the users through data abstraction.

05/12/2023 Shabnam Firdaus ACSAI-0402 -DBMS Unit-1 57


Three schema Architecture

• Three Schema Architecture for a Database System

05/12/2023 Shabnam Firdaus ACSAI-0402 -DBMS Unit-1 58


Three schema Architecture

05/12/2023 Shabnam Firdaus ACSAI-0402 -DBMS Unit-1 59


Three schema Architecture

• Objectives of Three schema Architecture


• 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.
• Different users need different views of the same data.
• The approach in which a particular user needs to see the data may change over
time.
• The users of the database should not worry about the physical implementation
and internal workings of the database such as data compression and encryption
techniques, hashing, optimization of the internal structures etc.
• All users should be able to access the same data according to their requirements.
• DBA should be able to change the conceptual structure of the database without
affecting the user's
• Internal structure of the database should be unaffected by changes to physical
aspects of the storage.

05/12/2023 Shabnam Firdaus ACSAI-0402 -DBMS Unit-1 60


Three schema Architecture

Conceptual Schema
• The conceptual schema describes the design of a database at
the conceptual level. Conceptual level is also known as
logical level.
• The conceptual schema describes the structure of the whole
database.
• The conceptual level describes what data are to be stored in
the database and also describes what relationship exists
among those data.
• In the conceptual level, internal details such as an
implementation of the data structure are hidden.
• Programmers and database administrators work at this level.

05/12/2023 Shabnam Firdaus ACSAI-0402 -DBMS Unit-1 61


Three schema Architecture

View Layer
• Each view schema describes the database part
that a particular user group is interested and
hides the remaining database from that user
group.
• The view schema describes the end user
interaction with database systems.
• It also simplifies interaction with the user and it
provides many views or multiple views of the
same database.
05/12/2023 Shabnam Firdaus ACSAI-0402 -DBMS Unit-1 62
Example: University Database

Physical schema:
 Relations stored as unordered files.
 Index on first column of Students.
Conceptual schema:
 Students(sid: string, name: string, login: string, age: integer,
gpa:real)
 Courses(cid: string, cname:string, credits:integer)
 Enrolled(sid:string, cid:string, grade:string)
External Schema (View):
 View1- Course_info(cid:string,enrollment:integer)
 View2-studeninfo(id:int. name:string)

05/12/2023 Shabnam Firdaus ACSAI-0402 -DBMS Unit-1 63


Data Independence

• Data Independence is defined as a property of DBMS that helps you to


change the Database schema at one level of a database system without
requiring to change the schema at the next higher level.

• Data independence helps you to keep data separated from all programs
that make use of it.
• We know the main purpose of the three levels of data abstraction is to achieve
data independence. If the database changes and expands over time, it is very
important that the changes in one level should not affect the data at other levels of
the database. This would save time and cost required when changing the database.
• There are two levels of data independence based on three levels of abstraction.
These are as follows −
• Physical Data Independence
• Logical Data Independence
 One of the most important benefits of using a DBMS!

05/12/2023 Shabnam Firdaus ACSAI-0402 -DBMS Unit-1 64


Data Independence

05/12/2023 Shabnam Firdaus ACSAI-0402 -DBMS Unit-1 65


Physical Data Independence

• Physical data independence can be defined as the capacity to


change the internal schema without having to change the
conceptual schema.

• 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.

• Physical data independence is used to separate conceptual


levels from the internal levels.

• Physical data independence occurs at the logical interface level.

05/12/2023 Shabnam Firdaus ACSAI-0402 -DBMS Unit-1 66


Physical Data Independence (contd..)

• Due to Physical independence, any of the below change will


not affect the conceptual layer.
– Using a new storage device like Hard Drive or Magnetic
Tapes
– Modifying the file organization technique in the Database
– Switching to different data structures.
– Changing the access method.
– Modifying indexes.
– Changes to compression techniques or hashing algorithms.
– Change of Location of Database from say C drive to D Drive

05/12/2023 Shabnam Firdaus ACSAI-0402 -DBMS Unit-1 67


Logical Data Independence

• Logical view of data is the user view of the data. It presents data in
the form that can be accessed by the end users.
• Logical data independence refers characteristic of being able to
change the conceptual schema without having to change the
external schema.

• Logical data independence is used to separate the external level


from the conceptual view.

• If we do any changes in the conceptual view of the data, then the


user view of the data would not be affected.

• Logical data independence occurs at the user interface level.

05/12/2023 Shabnam Firdaus ACSAI-0402 -DBMS Unit-1 68


Logical Data Independence (contd..)

• Due to Logical independence, any of the below


change will not affect the external layer.
– Add/Modify/Delete a new attribute, entity or
relationship is possible without a rewrite of
existing application programs
– Merging two records into one
– Breaking an existing record into two or more
records

05/12/2023 Shabnam Firdaus ACSAI-0402 -DBMS Unit-1 69


Short Quiz

1. Which of the following is known as a set of entities of the same


type that share same properties, or attributes?
a) Relation set
b) Tuples
c) Entity set
d) Entity Relation model

2. The values appearing in given attributes of any tuple in the


referencing relation must likewise occur in specified attributes
of at least one tuple in the referenced relation, according to
_____________________ integrity constraint.
a) Referential
b) Primary
c) Referencing
d) Specific
05/12/2023 Shabnam Firdaus ACSAI-0402 -DBMS Unit-1 70
Lecture 3
• DATA BASE LANGUAGES

• Data Definition Language (DDL)


• Data Manipulation Language
• Data Control Language

• Transaction Control Language (TCL)


Shabnam Firdaus ACSAI-0402 -DBMS Unit-1

05/12/2023 71
DATA BASE LANGUAGE (CO1)

• A DBMS has appropriate languages and interfaces to express


database queries and updates.
• Database languages can be used to read, store and update the
data in the database.
• Two classes of languages
– Procedural – user specifies what data is required and how
to get those data
– Declarative (nonprocedural) – user specifies what data is
required without specifying how to get those data
• SQL is the most widely used query language

05/12/2023 Shabnam Firdaus ACSAI-0402 -DBMS Unit-1 72


Topic- Database Language Objective

1. DDL stands for Data Definition Language. DML stands for


Data Manipulation Language. DDL statements are used to
create database, schema, constraints, users, tables etc. DML
statement is used to insert, update or delete the records.

2. DCL (Data Control Language) includes commands like GRANT


and REVOKE, which are useful to give “rights & permissions.”

3. Transaction control language or TCL commands deal with


the transaction within the database.

4. Data Query Language (DQL) is used to fetch the data from


the database.

05/12/2023 Shabnam Firdaus ACSAI-0402 -DBMS Unit-1 73


DATA BASE LANGUAGE

05/12/2023 Shabnam Firdaus ACSAI-0402 -DBMS Unit-1 74


Data Definition Language (DDL)

• DDL stands for Data Definition Language. It is used to


define database structure or pattern.
• It is used to create schema, tables, indexes,
constraints, etc. in the database.
• Using the DDL statements, you can create the
skeleton of the database.
• Data definition language is used to store the
information of metadata like the number of tables
and schemas, their names, indexes, columns in each
table, constraints, etc.

05/12/2023 Shabnam Firdaus ACSAI-0402 -DBMS Unit-1 75


Data Definition Language (DDL)

• Here are some tasks that come under DDL:


– Create: It is used to create objects in the database.
– Alter: It is used to alter the structure of the database.
– Drop: It is used to delete objects from the database.
– Truncate: It is used to remove all records from a table.
– Rename: It is used to rename an object.
– Comment: It is used to comment on the data dictionary.

These commands are used to update the database schema


that's why they come under Data definition language.

05/12/2023 Shabnam Firdaus ACSAI-0402 -DBMS Unit-1 76


Data Manipulation Language (DML)

• DML stands for Data Manipulation Language. It is used for accessing


and manipulating data in a database. It handles user requests.
• Here are some tasks that come under DML:
– Select: It is used to retrieve data from a database.
– Insert: It is used to insert data into a table.
– Update: It is used to update existing data within a table.
– Delete: It is used to delete all records from a table.
– Merge: It performs UPSERT operation, i.e., insert or update
operations.
– Call: It is used to call a structured query language or a Java
subprogram.
– Explain Plan: It has the parameter of explaining data.
– Lock Table: It controls concurrency.

05/12/2023 Shabnam Firdaus ACSAI-0402 -DBMS Unit-1 77


Data Control Language (DCL)

• DCL stands for Data Control Language. It is used to retrieve the


stored or saved data.
• The DCL execution is transactional. It also has rollback parameters.
(But in Oracle database, the execution of data control language does
not have the feature of rolling back.)

• Here are some tasks that come under DCL:


– Grant: It is used to give user access privileges to a database.
– Revoke: It is used to take back permissions from the user.
There are the following operations which have the authorization of
Revoke:

• CONNECT, INSERT, USAGE, EXECUTE, DELETE, UPDATE and SELECT.

05/12/2023 Shabnam Firdaus ACSAI-0402 -DBMS Unit-1 78


Transaction Control Language (TCL)

• TCL is used to run the changes made by the DML


statement. TCL can be grouped into a logical
transaction.

• Here are some tasks that come under TCL:


– Commit: It is used to save the transaction on the
database.
– Rollback: It is used to restore the database to
original since the last Commit.

05/12/2023 Shabnam Firdaus ACSAI-0402 -DBMS Unit-1 79


Delete, Drop and Truncate
TRUNCATE Command
DELETE Command DROP Command

Language The DELETE command is Data Manipulation The DROP command is Data The TRUNCATE command is a Data
Language Command. Definition Language Command. Definition Language Command.

The DELETE command deletes one or more The DROP Command drops the The TRUNCATE Command deletes all the
Use existing records from the table in the rows from the existing table, leaving the
database. complete table from the database. row with the column names.

We can restore any deleted row or multiple We cannot get the complete table We cannot restore all the deleted rows
Transition rows from the database using the deleted from the database using from the database using the ROLLBACK
ROLLBACK command. the ROLLBACK command. command.

The DELETE command does not free the The DROP command removes the The TRUNCATE command does not free
Memory Space space allocated for the table from the space allocated for the table from
allocated space of the table from memory. memory. memory.

The DROP Command has faster


performance than DELETE The TRUNCATE command works faster
The DELETE command performs slower
than the DROP command and TRUNCATE Command but not as compared to than the DROP command and DELETE
Performance Speed the Truncate Command because command because it deletes all the
command as it deletes one or more rows the DROP command deletes the records from the table without any
based on a specific condition.
table from the database after condition.
deleting the rows.

We need ALTER permission on the


Permission DELETE permission is required to delete the schema to which the table belongs We need table ALTER permission to use
rows of the table. and CONTROL permission on the the TRUNCATE command.
table to use the DROP command.

DELETE FROM table_name WHERE


Syntax DROP TABLE table_name; TRUNCATE TABLE table_name;
condition;

05/12/2023 Shabnam Firdaus ACSAI-0402 -DBMS Unit-1 80


Short Quiz

1.  The ability to query data, as well as insert, delete, and alter


tuples, is offered by ____________
a) TCL (Transaction Control Language)
b) DCL (Data Control Language)
c) DDL (Data Definition Langauge)
d) DML (Data Manipulation Langauge)

2. Which command is used to remove a relation from an SQL?


a) Drop table
b) Delete
c) Purge
d) Remove
05/12/2023 Shabnam Firdaus ACSAI-0402 -DBMS Unit-1 81
Short Quiz

1.Explain the terms database and DBMS. Also,


mention the different types of DBMS.
2.What are the advantages of DBMS?
3.Mention the different languages present in
DBMS
4.What are the different levels of abstraction in
the DBMS?
5.Write Difference between schema and
instances.

05/12/2023 Shabnam Firdaus ACSAI-0402 -DBMS Unit-1 82


Lecture 4
• ER Model
• Entity and attributes

• Relationship and degree of relationship

• Mapping Cardinality
• Participation Constraint

• Keys in DBMS

Shabnam Firdaus ACSAI-0402 -DBMS Unit-1

05/12/2023 83
Topic- ER Model Objective

1. An entity relationship diagram gives a snapshot of how these


entities relate to each other. You could call it the blueprint that
underpins your business architecture, offering a visual
representation of the relationships between different sets of data
(entities).

2. An Entity Relationship (ER) Diagram is a type of flowchart


that illustrates how “entities” such as people, objects or concepts
relate to each other within a system.
3. It is a diagrammatic approach to database design,
where you represent real-world objects as entities
and mention relationships between them. 

Shabnam Firdaus ACSAI-0402 -DBMS


05/12/2023 84
Unit-1
Introduction of ER Model

• A database can be modeled as:


– a collection of entities,
– relationship among entities.
• An entity is an object that exists and is distinguishable from other
objects.

– Example: specific person, company, event, plant


• Entities have attributes
– Example: people have names and addresses

• An entity set is a set of entities of the same type that share the
same properties.
– Example: set of all persons, companies, trees, holidays

05/12/2023 Shabnam Firdaus ACSAI-0402 -DBMS Unit-1 85


Introduction of ER Model

• Entity: An entity is a real-world object having attributes, which


are nothing but characteristics of that particular object. For
example, an employee can be an entity. This particular entity can
have attributes such as empid, empname, etc.
• Entity Type: Entity type is nothing but a collection of entities,
having the same attributes. Generally, an entity type refers to
one or more related tables in a particular database. So, you can
understand, entity type as a characteristic which uniquely
identifies the entity. For example, An employee can have
attributes such as empid, empname, department, etc.
• Entity Set: An entity set is the collection of all the entities of a
particular entity type in a database. For example, a set of
employees, a set of companies, and a set of people can come
under an entity set.

05/12/2023 Shabnam Firdaus ACSAI-0402 -DBMS Unit-1 86


Entity Sets customer and loan

05/12/2023 Shabnam Firdaus ACSAI-0402 -DBMS Unit-1 87


Attributes

• An entity is represented by a set of attributes, that is descriptive


properties possessed by all members of an entity set.
Example: customer = (customer_id, customer_name, customer_street,
customer_city )
loan = (loan_number, amount )

• In ER diagram, attribute is represented by an oval.

• Domain – the set of permitted values for each attribute

05/12/2023 Shabnam Firdaus ACSAI-0402 -DBMS Unit-1 88


Attribute Type

• Key Attribute – The attribute which uniquely identifies each entity


in the entity set is called key attribute. For example, Roll_No will be
unique for each student. In ER diagram, key attribute is represented
by an oval with underlying lines.

• Composite Attribute – An attribute composed of many other


attribute is called as composite attribute. For example, Address
attribute of student Entity type consists of Street, City, State, and
Country. In ER diagram, composite attribute is represented by an
oval comprising of ovals.

05/12/2023 Shabnam Firdaus ACSAI-0402 -DBMS Unit-1 89


Attribute Type

• Multivalued Attribute – An attribute consisting more than one


value for a given entity. For example, Phone_No (can be more than
one for a given student). In ER diagram, multivalued attribute is
represented by double oval.

• Derived Attribute – An attribute which can be derived from other


attributes of the entity type is known as derived attribute. e.g.; Age
(can be derived from DOB). In ER diagram, derived attribute is
represented by dashed oval.

05/12/2023 Shabnam Firdaus ACSAI-0402 -DBMS Unit-1 90


Attribute Type

• The complete entity type Student with its attributes can be


represented as:

05/12/2023 Shabnam Firdaus ACSAI-0402 -DBMS Unit-1 91


Degree of Relationship Set

• In DBMS, a degree of relationship represents the number of entity


types that associate in a relationship.

• The number of different entity sets participating in a relationship


set is called as degree of a relationship set.

– Unary Relationship
– Binary Relationship
– n-ary Relationship

05/12/2023 Shabnam Firdaus ACSAI-0402 -DBMS Unit-1 92


Unary Relationship

• When there is only ONE entity set participating in a relation, the


relationship is called as unary relationship.

• For example, monitor is being selected from the students of the


class

05/12/2023 Shabnam Firdaus ACSAI-0402 -DBMS Unit-1 93


Binary Relationship

• When there are TWO entities set participating in a relation, the


relationship is called as binary relationship.

• For example, Student is enrolled in Course.

05/12/2023 Shabnam Firdaus ACSAI-0402 -DBMS Unit-1 94


n-ary Relationship

• When there are n entities set participating in a relation, the


relationship is called as n-ary relationship.

05/12/2023 Shabnam Firdaus ACSAI-0402 -DBMS Unit-1 95


Mapping Cardinalities/Degree

• Mapping cardinalities or cardinality ratio express the number of


entities to which another entity can be associated via a relationship
set.

05/12/2023 Shabnam Firdaus ACSAI-0402 -DBMS Unit-1 96


Mapping Cardinalities

Types of cardinality in between tables are:


•one-to-one
•one-to-many
•many-to-one
•many-to-many

1. One-to-one: In this type of cardinality mapping, an entity in A is


connected to at most one entity in B. Or we can say that a unit or item in B
is connected to at most one unit or item in A.

05/12/2023 Shabnam Firdaus ACSAI-0402 -DBMS Unit-1 97


Mapping Cardinalities

Example:
In a particular hospital, the surgeon department has one head of department. They both
serve one-to-one relationships.

2. One-to-many: In this type of cardinality mapping, an entity in A is associated with


any number of entities in B. Or we can say that one unit or item in B can be
connected to at most one unit or item in A.

05/12/2023 Shabnam Firdaus ACSAI-0402 -DBMS Unit-1 98


Mapping Cardinalities

Example:
A doctor can prescribe more than one medicine

3. Many-to-one: In this type of cardinality mapping, an entity in A is connected to


at most one entity in B. Or we can say a unit or item in B can be associated with any
number (zero or more) of entities or items in A.

05/12/2023 Shabnam Firdaus ACSAI-0402 -DBMS Unit-1 99


Mapping Cardinalities

Example:
In a particular hospital, multiple surgeries are done by a single surgeon. Such a
type of relationship is known as a many-to-one relationship.

05/12/2023 Shabnam Firdaus ACSAI-0402 -DBMS Unit-1 100


Mapping Cardinalities

4. Many-to-many:  In this type of cardinality mapping, an entity in A is associated


with any number of entities in B, and an entity in B is associated with any number of
entities in A.

Example:
In a particular company, multiple people work on multiple projects. They serve many-
to-many relationships.

05/12/2023 Shabnam Firdaus ACSAI-0402 -DBMS Unit-1 101


Participation Constraint

• Total Participation – Each entity in the entity set must participate in


the relationship. If each student must enroll in a course, the
participation of student will be total. Total participation is shown by
double line in ER diagram.
• 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 student, the participation of course will be partial.

05/12/2023 Shabnam Firdaus ACSAI-0402 -DBMS Unit-1 102


Participation Constraint (contd..)

• Using set, it can be represented as

• Every student in Student Entity set is participating in relationship but


there exists a course C4 which is not taking part in the relationship.

05/12/2023 Shabnam Firdaus ACSAI-0402 -DBMS Unit-1 103


Weak Entity Type & Identifying Relationship

• An entity type has a key attribute which uniquely identifies each


entity in the entity set.
• But there exists some entity type for which key attribute can’t be
defined. These are called Weak Entity type.
• For example, A company may store the information of dependents
(Parents, Children, Spouse) of an Employee.
• But the dependents don’t have existence without the employee.
• So Dependent will be weak entity type and Employee will be
Identifying Entity type for Dependent.

05/12/2023 Shabnam Firdaus ACSAI-0402 -DBMS Unit-1 104


Weak Entity Type & Identifying Relationship

• A weak entity type is represented by a double rectangle. The


participation of weak entity type is always total. The relationship
between weak entity type and its identifying strong entity type is
called identifying relationship and it is represented by double
diamond.

05/12/2023 Shabnam Firdaus ACSAI-0402 -DBMS Unit-1 105


05/12/2023 Shabnam Firdaus ACSAI-0402 -DBMS Unit-1 106
Keys in DBMS

• KEYS in DBMS is an attribute or set of attributes which helps you to


identify a row(tuple) in a 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.
Example:-
Employee ID FirstName LastName
11 Andrew Johnson
22 Tom Wood
33 Alex Hale
• In the above-given example, employee ID is a primary key because
it uniquely identifies an employee record. In this table, no other
employee can have the same employee ID.

05/12/2023 Shabnam Firdaus ACSAI-0402 -DBMS Unit-1 107


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 in RDBMS ensure that you can uniquely identify a table record
despite these challenges.
• Allows you to establish a relationship between and identify the
relation between tables
• Help you to enforce identity and integrity in the relationship.

05/12/2023 Shabnam Firdaus ACSAI-0402 -DBMS Unit-1 108


Types of Keys in DBMS

There are mainly seven different types of Keys in DBMS and each key
has it’s different functionality:
– Super Key – A super key is a group of single or multiple keys
which identifies rows in a table.
– Primary Key – is a column or group of columns in a table that
uniquely identify every row in that table.
– Candidate Key – is a set of attributes that uniquely identify
tuples in a table. Candidate Key is a super key with no
repeated attributes.
– Alternate Key – is a column or group of columns in a table that
uniquely identify every row in that table.

05/12/2023 Shabnam Firdaus ACSAI-0402 -DBMS Unit-1 109


Types of Keys in DBMS (contd..)

– 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 between
two different instances of an entity.
– Compound Key – has two or more attributes that allow
you to uniquely recognize a specific record. It is
possible that each column may not be unique by itself
within the database.
– Composite Key – is a combination of two or more
columns that uniquely identify rows in a table. The
combination of columns guarantees uniqueness,
though individual uniqueness is not guaranteed.

05/12/2023 Shabnam Firdaus ACSAI-0402 -DBMS Unit-1 110


Super key

• A superkey is a group of single or multiple keys which identifies


rows in a table. A Super key may have additional attributes that are
not needed for unique identification.
Example:
EmpSSN EmpNum Empname
9812345098 AB05 Shown
9876512345 AB06 Roslyn
199937890 AB07 James

• In the above-given example, EmpSSN and EmpNum name are


superkeys.

05/12/2023 Shabnam Firdaus ACSAI-0402 -DBMS Unit-1 111


Primary Key

• PRIMARY KEY in DBMS is a column or group of columns in a table


that uniquely identify every row in that table. The Primary Key can’t
be a duplicate meaning the same value can’t appear more than
once in the table. A table cannot have more than one primary key.
Example:
StudID Roll No First Name LastName Email
1 11 Tom Price [email protected]
2 12 Nick Wright [email protected]
3 13 Dana Natan [email protected]

• In the following example, StudID is a Primary Key.

05/12/2023 Shabnam Firdaus ACSAI-0402 -DBMS Unit-1 112


Primary Key (contd..)

Rules for defining Primary key:


• Two rows can’t have the same primary key value
• The primary key field cannot be null.
• The value in a primary key column can never be modified or
updated if any foreign key refers to that primary key.

05/12/2023 Shabnam Firdaus ACSAI-0402 -DBMS Unit-1 113


Alternate key

• ALTERNATE KEYS is a column or group of columns in a table that


uniquely identify every row in that table. A table can have multiple
choices for a primary key but only one can be set as the primary
key. All the keys which are not primary key are called an Alternate
Key.
Example:
StudID Roll No First Name LastName Email
1 11 Tom Price [email protected]
2 12 Nick Wright [email protected]
3 13 Dana Natan [email protected]
• In this table, StudID, Roll No, Email are qualified to become a
primary key. But since StudID is the primary key, Roll No, Email
becomes the alternative key.

05/12/2023 Shabnam Firdaus ACSAI-0402 -DBMS Unit-1 114


Candidate Key

• CANDIDATE KEY in SQL is a set of attributes that uniquely identify


tuples in a table. Candidate Key is a super key with no repeated
attributes. The Primary key should be selected from the candidate
keys. Every table must have at least a single candidate key. A table
can have multiple candidate keys but only a single primary key.
Example:
StudID Roll No First Name LastName Email
1 11 Tom Price [email protected]
2 12 Nick Wright [email protected]
3 13 Dana Natan [email protected]

• Candidate key Example: In the given table Stud ID, Roll No, and
email are candidate keys which help us to uniquely identify the
student record in the table.

05/12/2023 Shabnam Firdaus ACSAI-0402 -DBMS Unit-1 115


Candidate Key (contd..)

Properties of Candidate key:


• It must contain unique values
• Candidate key in SQL may have multiple attributes
• Can contain null values
• It should contain minimum fields to ensure uniqueness
• Uniquely identify each record in a table

05/12/2023 Shabnam Firdaus ACSAI-0402 -DBMS Unit-1 116


Foreign key

• FOREIGN KEY is an attribute that creates a relationship between two


tables. The purpose of Foreign keys is to maintain data integrity and
allow navigation between two different instances of an entity. It
acts as a cross-reference between two tables as it references the
primary key of another table.
Example:
Persons Table orders
Person LastNa FirstNa Age OrderI OrderNum PersonID
ID me me D ber
1 Hansen Ola 30 1 77895 3
2 Svends Tove 23 2 44678 3
on
3 Petters Kari 20 3 22456 2
en 4 24562 1

05/12/2023 Shabnam Firdaus ACSAI-0402 -DBMS Unit-1 117


Foreign key (contd..)
• "PersonID" column in the "Orders" table points to the "PersonID" column in the
"Persons" table.
• The "PersonID" column in the "Persons" table is the PRIMARY KEY in the "Persons"
table.
• The "PersonID" column in the "Orders" table is a FOREIGN KEY in the "Orders"
table.
• The FOREIGN KEY constraint prevents invalid data from being inserted into the
foreign key column, because it has to be one of the values contained in the parent
table.

• Syntax:
CREATE TABLE Orders (
OrderID int NOT NULL,
OrderNumber int NOT NULL,
PersonID int,
PRIMARY KEY (OrderID),
FOREIGN KEY (PersonID) REFERENCES Persons(PersonID));
• This concept is also known as Referential Integrity.
05/12/2023 Shabnam Firdaus ACSAI-0402 -DBMS Unit-1 118
Compound key

• COMPOUND KEY has two or more attributes that allow you to uniquely
recognize a specific record. It is possible that each column may not be
unique by itself within the database. However, when combined with
the other column or columns the combination of composite keys
become unique.
Example:
OrderNo PorductID Product Name Quantity
B005 JAP102459 Mouse 5
B005 DKT321573 USB 10
B005 OMG446789 LCD Monitor 20
B004 DKT321573 USB 15
B002 OMG446789 Laser Printer 3

• In this example, OrderNo and ProductID can’t be a primary key as it


does not uniquely identify a record. However, a compound key of Order
ID and Product ID could be used as it uniquely identified each record.
05/12/2023 Shabnam Firdaus ACSAI-0402 -DBMS Unit-1 119
Composite key

• COMPOSITE KEY is a combination of two or more columns that


uniquely identify rows in a table. The combination of columns
guarantees uniqueness, though individually uniqueness is not
guaranteed. Hence, they are combined to uniquely identify records
in a table.

• The difference between compound and the composite key is that


any part of the compound key can be a foreign key, but the
composite key may or maybe not a part of the foreign key.

05/12/2023 Shabnam Firdaus ACSAI-0402 -DBMS Unit-1 120


Difference b/w Primary key & Foreign key

Primary Key Foreign Key

Helps you to uniquely identify a record in It is a field in the table that is the primary
the table. key of another table.

A foreign key may accept multiple null


Primary Key never accept null values.
values.

Primary key is a clustered index and data A foreign key cannot automatically create
an index, clustered or non-clustered.
in the DBMS table are physically organized
However, you can manually create an
in the sequence of the clustered index. index on the foreign key.

You can have the single Primary key in a You can have multiple foreign keys in a
table. table.

05/12/2023 Shabnam Firdaus ACSAI-0402 -DBMS Unit-1 121


Short Quiz

Q. Given the basic ER and relational models, which of the following is


INCORRECT?
answer choices
1. An attribute of an entity can have more than one value.
2. An attribute of an entity can be composite.
3. In a row of a relational table, an attribute can have more than one
value.
4. In a row of a relational table, an attribute can have exactly one value
or a NULL value.

Q.  Which type of entity cannot exist in the database unless another type
of entity also exists in the database, but does not require that the
identifier of that other entity be included as part of its own identifier?

5. Weak entity
6. Strong entity
7. ID-dependent entity
8. ID- independent entity
05/12/2023 Shabnam Firdaus ACSAI-0402 -DBMS Unit-1 122
Lecture 6
• Generalization, Specialization and Aggregation
• Reduction of an ER diagram to tables

• Examples of ER Diagram

Shabnam Firdaus ACSAI-0402 -DBMS Unit-1

05/12/2023 123
Topic- Generalization, Specialization and Aggregation
Objective

1. Generalization of Entities helps in establishing relationships between the


tables, as they have common attributes to be identified. It makes the
structuring of the database management simpler and easy to identify all the
relevant attributes.

2. Specialization helps in defining the set of subclasses of the entity type. Also,


it helps in establishing extra specific attributes with all subclasses and added
specific relationship types between each subclass and the other entity types
or the other subclasses.

3. Inheritance is an important feature of Generalization and Specialization.


It allows lower-level entities to inherit the attributes of higher-level entities.
For example, the attributes of a Person class such as name, age, and gender
can be inherited by lower-level entities such as Student or Teacher.
Shabnam Firdaus ACSAI-0402 -DBMS Unit-
05/12/2023 1 124
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.

• 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).

05/12/2023 Shabnam Firdaus ACSAI-0402 -DBMS Unit-1 125


Example:

05/12/2023 Shabnam Firdaus ACSAI-0402 -DBMS Unit-1 126


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.

• 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).

05/12/2023 Shabnam Firdaus ACSAI-0402 -DBMS Unit-1 127


Example:

05/12/2023 Shabnam Firdaus ACSAI-0402 -DBMS Unit-1 128


Aggregation

• Aggregation refers to the process by which entities are


combined to form a single meaningful entity.
• The specific entities are combined because they do not make
sense on their own. To establish a single entity, aggregation
creates a relationship that combines these entities.

05/12/2023 Shabnam Firdaus ACSAI-0402 -DBMS Unit-1 129


Reduction of an ER diagrams to tables Objectives

1. Mapping an Entity Relationship (ER) model gives a good overview of


the design of a system with the goal of making the system easier to
understand at a technical level.

2. The ER diagrams can be mapped to a relation schema, which means


we can clearly display the relationship between its members.

3. An Entity Relationship (ER) Diagram is a type of flowchart


that illustrates how “entities” such as people, objects or concepts
relate to each other within a system.

05/12/2023 Shabnam Firdaus ACSAI-0402 -DBMS Unit-1 130


Reduction of an ER diagrams to tables

Rule-01: For Strong Entity Set With Only Simple Attributes


• A strong entity set with only simple attributes will require only one
table in relational model.
– Attributes of the table will be the attributes of the entity set.
– The primary key of the table will be the key attribute of the
entity set.

Schema : Student ( Roll_no , Name , Sex )

05/12/2023 Shabnam Firdaus ACSAI-0402 -DBMS Unit-1 131


RULE-02

Rule-02: For Strong Entity Set With Composite Attributes


• A strong entity set with any number of composite attributes will
require only one table in relational model.
• While conversion, simple attributes of the composite attributes are
taken into account and not the composite attribute itself.

Schema : Student ( Roll_no , First_name , Last_name , House_no , Street , City )


05/12/2023 Shabnam Firdaus ACSAI-0402 -DBMS Unit-1 132
RULE-03

Rule-03: For Strong Entity Set With Multi Valued Attributes


• A strong entity set with any number of multi valued attributes will
require two tables in relational model.
– One table will contain all the simple attributes with the primary
key.
– Other table will contain the primary key and all the multi valued
attributes.

Roll_no City Roll_no Mobile_no

05/12/2023 Shabnam Firdaus ACSAI-0402 -DBMS Unit-1 133


RULE-04

Rule-04: Translating Relationship Set into a Table


• A relationship set will require one table in the relational model.
• Attributes of the table are-
– Primary key attributes of the participating entity sets
– Its own descriptive attributes if any.
– Set of non-descriptive attributes will be the primary key.
exper
ience

Schema : Works in ( Emp_no , Dept_id ,


experience )
05/12/2023 Shabnam Firdaus ACSAI-0402 -DBMS Unit-1 134
RULE-05

Rule-05: For Binary Relationships With Cardinality Ratios

• The following four cases are possible-

– Case-01: Binary relationship with cardinality ratio m:n

– Case-02: Binary relationship with cardinality ratio 1:n

– Case-03: Binary relationship with cardinality ratio m:1

– Case-04: Binary relationship with cardinality ratio 1:1


05/12/2023 Shabnam Firdaus ACSAI-0402 -DBMS Unit-1 135
RULE-05 (contd..)

Case-01: For Binary Relationship With Cardinality Ratio m:n

• Here, three tables will be required-


1. A ( a1 , a2 )
2. R ( a1 , b1 )
3. B ( b1 , b2 )

05/12/2023 Shabnam Firdaus ACSAI-0402 -DBMS Unit-1 136


RULE-05 (contd..)

Case-02: For Binary Relationship With Cardinality Ratio 1:n

• Here, two tables will be required-


1. A ( a1 , a2 )
2. BR ( a1 , b1 , b2 )

NOTE- Here, combined table will be drawn for the entity set B and
relationship set R.

05/12/2023 Shabnam Firdaus ACSAI-0402 -DBMS Unit-1 137


RULE-05 (contd..)

Case-03: For Binary Relationship With Cardinality Ratio m:1

• Here, two tables will be required-


1. AR ( a1 , a2 , b1 )
2. B ( b1 , b2 )

NOTE- Here, combined table will be drawn for the entity set A and
relationship set R.

05/12/2023 Shabnam Firdaus ACSAI-0402 -DBMS Unit-1 138


RULE-05 (contd..)

Case-04: For Binary Relationship With Cardinality Ratio 1:1

• Here, two tables will be required. Either combine ‘R’ with ‘A’ or ‘B’

• Way-01:
1. AR ( a1 , a2 , b1 )
2. B ( b1 , b2 )
• Way-02:
1. A ( a1 , a2 )
2. BR ( a1 , b1 , b2 )

05/12/2023 Shabnam Firdaus ACSAI-0402 -DBMS Unit-1 139


RULE-06

Rule-06: For Binary Relationship With Both Cardinality Constraints


and Participation Constraints-

• Case-01: For Binary Relationship With Cardinality Constraint and


Total Participation Constraint From One Side

• Case-02: For Binary Relationship With Cardinality Constraint and


Total Participation Constraint From Both Sides-

05/12/2023 Shabnam Firdaus ACSAI-0402 -DBMS Unit-1 140


RULE-06 (contd..)

Case-01: For Binary Relationship With Cardinality Constraint and


Total Participation Constraint From One Side

• Because cardinality ratio = 1 : n , so we will combine the entity set B


and relationship set R.
• Then, two tables will be required-
1. A ( a1 , a2 )
2. BR ( a1 , b1 , b2 )
• Because of total participation, foreign key a1 has acquired NOT
NULL constraint, so it can’t be null now.
05/12/2023 Shabnam Firdaus ACSAI-0402 -DBMS Unit-1 141
RULE-06 (contd..)

Case-02: For Binary Relationship With Cardinality Constraint and


Total Participation Constraint From Both Sides
• If there is a key constraint from both the sides of an entity set with
total participation, then that binary relationship is represented
using only single table.

• Here, Only one table is required.


1. ARB ( a1 , a2 , b1 , b2 )

05/12/2023 Shabnam Firdaus ACSAI-0402 -DBMS Unit-1 142


RULE-07

Rule-07: For Binary Relationship With Weak Entity Set


• Weak entity set always appears in association with identifying
relationship with total participation constraint.

• Here, two tables will be required-


1. A ( a1 , a2 )
2. BR ( a1 , b1 , b2 )

05/12/2023 Shabnam Firdaus ACSAI-0402 -DBMS Unit-1 143


Examples of ER Diagram

05/12/2023 Shabnam Firdaus ACSAI-0402 -DBMS Unit-1 144


ER Diagram For Department

05/12/2023 Shabnam Firdaus ACSAI-0402 -DBMS Unit-1 145


ER Diagram for Company

05/12/2023 Shabnam Firdaus ACSAI-0402 -DBMS Unit-1 146


Summary of Conceptual Design

• Conceptual design follows requirements analysis,


– Yields a high-level description of data to be stored
• ER model popular for conceptual design
– Constructs are expressive, close to the way people think about
their applications.
• Basic constructs: entities, relationships, and attributes (of entities
and relationships).
• Some additional constructs: weak entities, ISA hierarchies, and
aggregation.
• Note: There are many variations on ER model.

05/12/2023 Shabnam Firdaus ACSAI-0402 -DBMS Unit-1 147


Summary of ER (Contd.)

• ER design is subjective. There are often many ways to model a given


scenario! Analyzing alternatives can be tricky, especially for a large
enterprise. Common choices include:
– Entity vs. attribute, entity vs. relationship, binary or n-ary
relationship, whether or not to use ISA hierarchies, and whether
or not to use aggregation.
• Ensuring good database design: resulting relational schema should
be analyzed and refined further. FD information and normalization
techniques are especially useful.

05/12/2023 Shabnam Firdaus ACSAI-0402 -DBMS Unit-1 148


Daily Quiz

• Define Database System.


• What do you understand by data independence?
• Explain types of attributes in ER diagram.
• What is generalization.
• What do you understand by primary key?
• Explain participation cardinality.

05/12/2023 Shabnam Firdaus ACSAI-0402 -DBMS Unit-1 149


Weekly Assignment

• Define: Data, Database, and Database System.


• What is data independence? What are differences between Logical
Data Independence and Physical Data Independence?
• Give example of Simple, Composite, Single –valued and Multi-
valued attributes of an entity.
• What is the difference between Generalization & Specialization
with respect to Database?
• What is difference between total and partial participation? Explain
by suitable example.
• Construct an E-R diagram for a hospital with a set of patients and a
set of medical doctors. Associated with each patient, a log of the
various tests and examinations conducted.

05/12/2023 Shabnam Firdaus ACSAI-0402 -DBMS Unit-1 150


Topic Links

1. https://www.geeksforgeeks.org/last-minute-notes-dbms/
2. https://www.geeksforgeeks.org/quiz-corner-gq/#DBMS%20Mock%20Tests
3. https://www.geeksforgeeks.org/commonly-asked-dbms-interview-questio
ns/
4. https://www.geeksforgeeks.org/commonly-asked-dbms-interview-questio
ns-set-2/

05/12/2023 Shabnam Firdaus ACSAI-0402 -DBMS Unit-1 151


MCQ s

• The entity relationship set is represented in E-R diagram as


a) Double diamonds
b) Undivided rectangles
c) Dashed lines
d) Diamond

• The Rectangles divided into two parts represents


a) Entity set
b) Relationship set
c) Attributes of a relationship set
d) Primary key

05/12/2023 Shabnam Firdaus ACSAI-0402 -DBMS Unit-1 152


MCQ s

• An entity set that does not have sufficient attributes to form a


primary key is termed a __________
a) Strong entity set
b) Variant set
c) Weak entity set
d) Variable set

• What term is used to refer to a specific record in your music


database; for instance; information stored about a specific album?
a) Relation
b) Instance
c) Table
d) Column

05/12/2023 Shabnam Firdaus ACSAI-0402 -DBMS Unit-1 153


MCQ s

• Which of the following is generally used for performing tasks like creating the
structure of the relations, deleting relation?
DML(Data Manipulation Language)
Query
Relational Schema
DDL(Data Definition Language)

• Which of the following provides the ability to query information from the database
and insert tuples into, delete tuples from, and modify tuples in the database?

DML(Data Manipulation Language)


DDL(Data Definition Language)
Query
Relational Schema

Shabnam Firdaus ACSAI-0402 -DBMS


05/12/2023 154
Unit-1
Glossary Questions

1. Attempt all the parts. Pick the correct option from glossary. [CO1]
(i) Double diamonds (ii) Database Management System (iii) Diamond (iv) Entity set
(a). _____________is the full form of DBMS.
(b). A weak relationship is represented in E-R diagram as___________.
(c) The Rectangles in E-R diagram represents____________________.
(d). The relationship is represented in E-R diagram as_____________.

2. Attempt all the parts. Pick the correct option from glossary. [CO1]
(i ) FALSE (ii) TRUE (iii)       Tuple (iv) Meta Data
(a) A row of a relation is known as____________.
(b)_____________________refers to the "data about data"?
(c) Alternate Key is a kind of partial key in DBMS, which is created when you don’t have any
natural primary key._______
(d) Generalization
05/12/2023 is a bottom-up Shabnam
approach.______
Firdaus ACSAI-0402 -DBMS Unit-1 155
Sessional Paper-1

Shabnam Firdaus ACSAI-0402 -DBMS


05/12/2023 156
Unit-1
Conti….

Shabnam Firdaus ACSAI-0402 -DBMS


05/12/2023 157
Unit-1
Conti….

Shabnam Firdaus ACSAI-0402 -DBMS


05/12/2023 158
Unit-1
Sessional Paper-2

Shabnam Firdaus ACSAI-0402 -DBMS


05/12/2023 159
Unit-1
Conti….

Shabnam Firdaus ACSAI-0402 -DBMS


05/12/2023 160
Unit-1
Conti….

Shabnam Firdaus ACSAI-0402 -DBMS


05/12/2023 161
Unit-1
Old University Question Paper

Shabnam Firdaus ACSAI-0402 -DBMS Unit-1

05/12/2023 162
Conti….

Shabnam Firdaus ACSAI-0402 -DBMS


05/12/2023 163
Unit-1
Conti….

Shabnam Firdaus ACSAI-0402 -DBMS


05/12/2023 164
Unit-1
Conti….

Shabnam Firdaus ACSAI-0402 -DBMS


05/12/2023 165
Unit-1
Old University Question Paper

Shabnam Firdaus ACSAI-0402 -DBMS Unit-1

05/12/2023 166
Conti….

Shabnam Firdaus ACSAI-0402 -DBMS


05/12/2023 167
Unit-1
Conti….

Shabnam Firdaus ACSAI-0402 -DBMS


05/12/2023 168
Unit-1
Old Question Papers

• http://www.aktuonline.com/papers/btech-cs-5-sem-data-base-man
agement-system-KCS501-2020.pdf
• http://www.aktuonline.com/papers/btech-cs-5-sem-database-man
agement-system-KCS-501-2018-19.pdf
• http://www.aktuonline.com/papers/btech-cs-5-sem-database-man
agement-system-ncs-502-2017-18.pdf
• http://www.aktuonline.com/papers/btech-cs-5-sem-database-man
agement-system-ncs-502-2016-17.pdf

05/12/2023 Shabnam Firdaus ACSAI-0402 -DBMS Unit-1 169


Expected Questions for University Exam

• Explain types of attributes in ER diagram.


• Explain the difference between a weak and a strong entity set with
example.
• Discuss three level of abstractions or schemas architecture of
DBMS.
• Define constraint and its types in DBMS.
• Compare Generalization, Specialization and aggregation with
suitable examples.
• Draw overall structure of DBMS and explain its components in brief.
• Construct an E-R diagram for a hospital with a set of patients and a
set of medical doctors. Associated with each patient, a log of the
various tests and examinations conducted.

05/12/2023 Shabnam Firdaus ACSAI-0402 -DBMS Unit-1 170


Recap of Unit

• Knowledge of database architecture.

• Knowledge of Entity Relationship model and its concepts.

• Databse V/S File system.

05/12/2023 Shabnam Firdaus ACSAI-0402 -DBMS Unit-1 171


Thank You

05/12/2023 Shabnam Firdaus ACSAI-0402 -DBMS Unit-1 172

You might also like