SlideShare a Scribd company logo
1 of 177
2
Course Outcome Will be covered in
this lecture
Department of Computer Science and Engineering (CSE)
CO1: To make student learn all
core subjects of respective
engineering background
Contents of the Syllabus
3
Department of Computer Science and Engineering (CSE)
Unit-1 Data Base Management Systems Contact Hours:4
CHAPTER
1.1
Introduction and applications of DBMS, Purpose of data base, Data, Independence,
Database System architecture- levels.
CHAPTER
1.2
Structure of relational databases, Domains, Relations, Relational algebra – fundamental
operators and syntax, relational algebra queries, tuple relational calculus.
CHAPTER
1.3
Basic concepts, Design process, constraints, Keys, Design issues, E-R diagrams, weak
entity sets, extended E-R features – generalization, specialization, aggregation, reduction
to E-R database schema
CHAPTER
1.4
Functional Dependency – definition, trivial and non-trivial FD, closure of FD set, closure of
attributes, irreducible set of FD, Normalization – 1Nf, 2NF, 3NF, Decomposition using FD-
dependency preservation, BCNF, Multi- valued dependency, 4NF, Join dependency and
5NF
Contact
Hours:4
Contents of the Syllabus
4
Department of Computer Science and Engineering (CSE)
Unit-2 Structured Query Language Contact Hours:4
CHAPTER 2.1 Basics of SQL, DDL, DML, DCL, structure – creation, alteration, defining constraints –
Primary key, foreign key, unique, not null, check, IN operator,
Functions - aggregate functions, Built-in functions –numeric, date, string functions, set
operations, sub-queries, correlated sub-queries, use of group by, having, order by, join
and its types, Exist, Any, All, view and its types. transaction control commands – Commit,
Rollback, Save point
CHAPTER 2.2 Cursors, Stored Procedures, Stored Function, Database Triggers
Unit-3 Views , Packages and procedures , triggers, Transection
management and concurrency control.
Contact Hours:4
CHAPTER 3.1 Package, Procedures and Triggers: Parts of procedures, Parameter modes, Advantages of
procedures, Syntax for creating triggers, Types of triggers, package specification and package
body, developing a package, Bodiless package, Advantages of packages.
Contents of the Syllabus
CHAPTER 3.2
Transaction Management and Concurrency Control: Introduction to Transaction
Processing, Properties of Transactions, Serializability and Recoverability, Need for
Concurrency Control, Locking Techniques, Time Stamping Methods, Optimistic
Techniques, Granularity of Data items, Database Recovery of database: Introduction,
Need for Recovery, Types of errors, Recovery Techniques.
Department of Computer Science and Engineering (CSE)
University Institute of Engineering (UIE)
OBJECTIVES
At the completion of this Chapter , students should be able
to do the following:
• Understand the role of a database
management system in an organization.
• Understand basic database concepts, including the
structure and operation of the relational data model.
Department of Computer Science and Engineering
(CSE)
University Institute of Engineering
File system vs. Database
system
File System-
• Data storage traditionally used individual, unrelated files, sometimes
called flat files.
• In the past, each application program in an organization used its own file.
• In a university, for example, each department might have its own set of
files: the record office kept a file about the student information and their
grades, the scheduling office kept the name of the professors and the
courses they were teaching, the payroll department kept its own file about
the whole staff and so on.
• Today, however, all of these flat files can be combined in a single
entity; the database for the whole university
Department of Computer Science and Engineering
(CSE)
University Institute of Engineering
Data
vs.
Informtion
Department of Computer Science and Engineering
(CSE)
University Institute of Engineering
Database Management System
(DBMS)
• The related information when placed is an organized form makes a database.
• The organization of data/information is necessary because unorganized information
has no meaning.
• Collection of interrelated data
• Set of programs to access the data
• DBMS contains information about a particular enterprise
• DBMS provides an environment that is both convenient and efficient to use.
• Database Applications:
– Banking: all transactions
– Airlines: reservations, schedules
– Universities: registration, grades
– Sales: customers, products, purchases
– Manufacturing: production, inventory, orders, supply chain
– Human resources: employee records, salaries, tax deductions
• Databases touch all aspects of our lives
Department of Computer Science and Engineering
(CSE)
University Institute of Engineering
Purpose of Database
System
• In the early days, database applications were built 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 provide a way of ensuring that changes
made to the database by authorized users do not result in a
loss of data consistency.
• Hard to add new constraints or change existing ones
Department of Computer Science and Engineering
(CSE)
University Institute of Engineering
Purpose of Database
System
• Drawbacks of using file systems (cont.)
– Atomicity of updates
• Failures may leave database in an inconsistent state with partial
updates carried out
• E.g. transfer of funds from one account to another should either
complete or not happen at all
– Concurrent access by multiple users
• Concurrent accessed needed for performance
• Uncontrolled concurrent accesses can lead to inconsistencies
– E.g. two people reading a balance and updating it at the same
time
– Security problems
• Database systems offer solutions to all the above problems
Department of Computer Science and Engineering
(CSE)
University Institute of Engineering
Disadvantages of Traditional File
system
• Data Redundancy
Since each application has its own data file, the
same data may have to be recorded and stored in
many files
For example-
Personal file and payroll file, both contain data on
employee name, designation etc. The result is
unnecessary duplicate or redundant data items. This
redundancy requires additional or higher storage
space, costs extra time and money, and requires
additional efforts to keep all files upto-date.
Department of Computer Science and Engineering
(CSE)
University Institute of Engineering
• Data Inconsistency
Data redundancy leads to data inconsistency especially when
data is to be updated. Data inconsistency occurs due to the
same data items that appear in more than one file do not get
updated simultaneously in each and every file.
• Lack of Data Integration
• Data Dependence
• Limited Data Sharing
• Poor Data Control
• Problem of Security
• Data Manipulation Capability is Inadequate
Disadvantages of Traditional File
system
Department of Computer Science and Engineering
(CSE)
Operations on
Databases
University Institute of Engineering
Department of Computer Science and Engineering
(CSE)
University Institute of Engineering
Advantages of
Databases
• Less redundancy
– In a flat-file system there is a lot of redundancy. For example, in the flat file
system for a university, the names of professors and students are stored in
more than one file.
• Inconsistency avoidance
When the same data is duplicated and changes are made at one site, which
is not propagated to the other site, it gives rise to inconsistency and the two
entries regarding the same data will not agree.
– If the same piece of information is stored in more than one place, then any
changes in the data need to occur in all places that data is stored.
Department of Computer Science and Engineering
(CSE)
University Institute of Engineering
• Efficiency
– A database is usually more efficient that a flat file system,
because a piece of information is stored in fewer locations.
• Data integrity
• Integrity of data means that data in database is always accurate, such that
incorrect information cannot be stored in database.
– In a database system it is easier to maintain data integrity, because a
piece of data is stored in fewer locations.
• Confidentiality
– It is easier to maintain the confidentiality of the information if the storage of
data is centralized in one location.
Advantages of
Databases
Department of Computer Science and Engineering
(CSE)
University Institute of Engineering
• Data can be shared
• Providing Backup and Recovery
• Standards can be enforced
• Restricting unauthorized access
• Solving enterprise requirement than individual requirement
Advantages of
Databases
Department of Computer Science and Engineering
(CSE)
University Institute of Engineering
Disadvantages of
DBMS
• Complexity
• Size
• Performance
• Higher impact of a
failure
• Cost of DBMS
• Additional Hardware
costs
• Cost of Conversion
Department of Computer Science and Engineering
(CSE)
University Institute of Engineering
Use a DBMS when this is
important
• persistent storage of data
• centralized control of data
• control of redundancy
• control of consistency and
integrity
• multiple user support
• sharing of data
• data documentation
• data independence
• control of access and security
• backup and recovery
Do not use a DBMS when
• the initial investment in hardware,
software, and training is too high
• the generality a DBMS provides is not
needed
• the overhead for security, concurrency
control, and recovery is too high
• data and applications are simple and
stable
• real-time requirements cannot be met by
it
• multiple user access is not needed
Department of Computer Science and Engineering
(CSE)
University Institute of Engineering
File
Management
e.g. COBOL or C++
Program
• Small systems
• Relatively Cheap
• Few Files
• Files are Files
• Simple Structure
• Redundant Data
• Chances of Inconsistency
• Isolated Data
• Little Preliminary Design
• Integrity Left to application
Programmer
• NO Security
• Simple, Primitive
backup/Recovery
• Often Single User
• Large systems
• Relatively Expensive
• Many Files
• Files are Tables
• Complex Structure
• Reduced Redundancy
• Consistent
• Data can be Shared
• Vast Preliminary Design
• Rigorous inbuilt Integrity
checking
• Rigorous Security
• Complex & Sophisticated
backup/Recovery
• Multiple Users
Database
Management
e.g. Oracle
BASIC DEFINITIONS
⮚Database: A collection of related data.
⮚Data: Known facts that can be recorded and have an implicit
meaning.
⮚Database Management System (DBMS): A software package/
system to facilitate the creation and maintenance of a computerized
database.
⮚Database System: The DBMS software together with the data
itself. Sometimes, the applications are also included.
Department of Computer Science and Engineering
(CSE)
Department of Computer Science and Engineering
(CSE)
University Institute of Engineering
Outcomes
• Differentiate database systems from file systems by
enumerating the features provided by database
systems and describe each in both function and
benefit.
• Define the terminology, features, classifications, and
characteristics embodied in database systems.
• Master the basic concepts and appreciate the
applications of database systems.
Department of Computer Science and Engineering
(CSE)
University Institute of Engineering
References
• Database System Concepts by Abraham
Silberschatz
• Database System Concepts by
Sudarshan, Korth Education)
(McGraw-Hill
• Fundamentals of Database System By
Elmasari &Navathe- Pearson Education
• http://ecomputernotes.com/database-system/rdbms
• https://www.tutorialspoint.com/sql/sql-rdbms-concepts.htm
• https://www.studytonight.com/dbms/rdbms-concept
Department of Computer Science and Engineering
(CSE)
University Institute of Engineering
(UIE)
Department of Computer Science and Engineering (CSE)
University Institute of Engineering (UIE)
OBJECTIVES
At the completion of this Chapter , students should be
able to do the following:
• Understand DBMS Architecture
• Appreciate the evolution of ANSI SPARC (3 level
architecture)
Department of Computer Science and Engineering (CSE)
University Institute of Engineering (UIE)
Introduction
ANSI
American National Standards Institute
SPARC
Standards Planning And Requirements Committee
• It is an abstract design standard for a Database Management
System (DBMS), first proposed in 1975.
Department of Computer Science and Engineering (CSE)
University Institute of Engineering (UIE)
Department of Computer Science and Engineering (CSE)
University Institute of Engineering (UIE)
Three-level architecture
• External level
• Conceptual level
• Internal level
• The Three Level Architecture has the aim of enabling users to
access the same data but with a personalized view of it. The
distancing of the internal level from the external level means that
users do not need to know how the data is physically stored in
the database. This level separation also allows the Database
Administrator (DBA) to change the database storage structures
without affecting the users' views.
Department of Computer Science and Engineering (CSE)
University Institute of Engineering (UIE)
Three-level architecture
• External Level (User Views): A user's view of the database describes
a part of the database that is relevant to a particular user. It excludes
irrelevant data as well as data which the user is not authorized to
access.
• Conceptual Level: The conceptual level is a way of describing
what data is stored within the whole database and how the data is
inter-related. The conceptual level does not specify how the data is
physically stored.
• Internal Level: The internal level involves how the database is
physically represented on the computer system. It describes how
the data is actually stored in the database and on the computer
hardware.
Department of Computer Science and Engineering (CSE)
University Institute of Engineering (UIE)
Objective of the three-level
architecture
• It allows independent customized user views: Each user should be
able to access the same data, but have a different customized view
of the data. These should be independent: changes to one view
should not affect others.
• It hides the physical storage details from users: Users should
not have to deal with physical database storage details.
• The database administrator should be able to change the
database storage structures without affecting the users’ views.
• The internal structure of the database should be unaffected by
changes to the physical aspects of the storage: For example, a
changeover to a new disk.
Department of Computer Science and Engineering (CSE)
University Institute of Engineering (UIE)
Database schemas
There are three different types of schema corresponding to the three
levels in the ANSI-SPARC architecture.
Schema is the structure of the database that defines the objects in the
database
• The external schemas describe the different external views
of the data and there may be many external schemas for a
given database.
• The conceptual schema describes all the data items and
relationships between them, together with integrity constraints
(later). There is only one conceptual schema per database.
• The internal schema at the lowest level contains definitions
of the stored records, the methods of representation, the
data fields, and indexes. There is only one internal schema
per database.
Department of Computer Science and Engineering
(CSE)
The
way
users
perceiv
e the
data.
University Institute of Engineering (UIE)
The way the
DBMS and OS
perceive the
data.
Department of Computer Science and Engineering (CSE)
University Institute of Engineering (UIE)
Mapping between views
• Three view-levels are described by means of three schemas.
• These schemas are stored in the data dictionary.
• In DBMS, each user refers only to its own external schema.
• Hence, the DBMS must transform a request on. a specified external schema into a
request against conceptual schema, and then into a request against internal schema
to store and retrieve data to and from the database.
• The process to convert a request (from external level) and the result between view
levels is called mapping.
• The mapping defines the correspondence between three view levels.
• The mapping description is also stored in data dictionary.
• The DBMS is responsible for mapping between these three types of schemas.
Department of Computer Science and Engineering (CSE)
University Institute of Engineering (UIE)
Mapping between views
There are two types of mapping.
(i) External-Conceptual mapping
• An external-conceptual mapping defines the correspondence between a particular
external view and the conceptual view.
• The external-conceptual mapping tells the DBMS which objects on the conceptual
level correspond to the objects requested on a particular user's external view.
• If changes are made to either an external view or conceptual view, then mapping
must be changed accordingly.
(ii) Conceptual-Internal mapping
• The conceptual-internal mapping defines the correspondence between the
conceptual view and the internal view, i.e. database stored on the physical storage
device.
• It describes how conceptual records are stored and retrieved to and from the
storage device.
Department of Computer Science and Engineering (CSE)
University Institute of Engineering (UIE)
Example
Department of Computer Science and Engineering (CSE)
University Institute of Engineering (UIE)
Data Independence
• The ability to modify a scheme definition in one level without
affecting a scheme definition in a higher level is called data
independence.
There are two kinds:
• Logical data independence
• Physical data independence
Department of Computer Science and Engineering (CSE)
University Institute of Engineering (UIE)
Data Independence
Logical data independence
• The ability to modify the conceptual scheme without causing
application programs to be rewritten.
• Immunity of external schemas to changes in the conceptual schema.
• The change would be absorbed by mapping
between external and conceptual levels.
Physical data independence
• The ability to modify the internal scheme or physical storage
structures and devices without affecting conceptual or external
schemas .
• Modifications at this level are usually to improve performance.
Logical data independence is difficult to achieve than
physical data independence.
Department of Computer Science and Engineering (CSE)
University Institute of Engineering (UIE)
Database Administrator (DBA)
• A database administrator (DBA) is an IT professional responsible for
the installation, configuration, upgrading, administration, monitoring,
maintenance, and security of databases in an organization.
Department of Computer Science and Engineering (CSE)
University Institute of Engineering (UIE)
Responsibilities of DBA
Makes decisions concerning the content of the database.
✔ Identify the entities of interest to the enterpriseand
to identify
information to be recorded about those entities
Plans storage structures and access strategies.
✔ How the data is to be represented in the database.
✔ Specify the representation by writing the storage structure definition
(using the internal data definition language).
✔ The associated mapping between the storage structure definition and the conceptual schema
must also be specified.
Provides support to users.
✔ Ensure that the data users require is available,and
to write the necessary external schemas.
✔ The mapping between any given eA1ernal schema and the conceptual' schema must also be
specified.
Department of Computer Science and Engineering (CSE)
University Institute of Engineering (UIE)
Responsibilities of DBA
Defines security and integrity checks.
✔ Providing the authorization and authentication checks such
that no
malicious users can access database and it must remain protected.
✔ DBA must also ensure the integrity of the database.
Interprets backup and recovery strategies.
✔ Define and implement an appropriate recovery
strategy to recover he
database from all types of failures.
Monitoring performance and responding to changes in requirements.
✔ DBA is responsible for so organizing the system as to get the performance that is
"best for the enterprise," and for making the appropriate adjustments as
requirements change.
Department of Computer Science and Engineering (CSE)
University Institute of Engineering (UIE)
Outcomes
• Analyze an information storage problem and derive an
information model expressed in the form of an entity
relation diagram and other optional analysis forms,
such as a data dictionary.
• Demonstrate an understanding of the relational data
model.
• Appreciate the roles & responsibilities of DBA.
Department of Computer Science and Engineering (CSE)
University Institute of Engineering (UIE)
References
• Database System Concepts by Abraham
Silberschatz
• Database System Concepts by
Sudarshan, Korth Education)
(McGraw-
Hill
• Fundamentals of Database SystemBy Elmasari
&Navathe- Pearson Education
• http://ecomputernotes.com/database-system/rdbms
• https://www.tutorialspoint.com/sql/sql-rdbms-concepts.htm
• https://www.studytonight.com/dbms/rdbms-concept
Department of Computer Science and Engineering (CSE)
University Institute of Engineering (UIE)
University Institute of Engineering (UIE)
46
Database
Management
System
CO
Number
Title Level
CO1 To perceive the significance and
implementation of a commercial
relational database system (Oracle)
by writing SQL using the system.
Remember
CO2 To understand the relational database
theory, and be able to write
relational algebra expressions for
queries
Understand
CO3 To identify the basic issues of
transaction processing and
concurrency control and find out its
solutions.
Analysis and
application
Course Outcome Will be covered in
this lecture
Department of Computer Science and Engineering (CSE)
University Institute of Engineering (UIE)
Department of Computer Science and Engineering (CSE)
Contents of the Syllabus
47
UNIT-I [10h]
Overview of Databases: Database concepts, DBMS, Data Base System Architecture (Three
Level ANSI-SPARC Architecture), Advantages and Disadvantages of DBMS, Data Independence, DBA
and Responsibilities of DBA, Relational Data Structure, Keys, Relations, Attributes, Schema and
Instances, Referential integrity, Entity integrity.
Data Models: Relational Model, Network Model, Hierarchical Model, ER Model: Design,
issues, Mapping constraints, ER diagram, Comparison of Models.
Relational Algebra & Relational Calculus: Introduction, Syntax, Semantics, Additional
operators, Grouping and Ungrouping, Relational comparisons, Tuple Calculus, Domain Calculus,
Calculus Vs Algebra, Computational capabilities.
UNIT-II [10h]
Functional dependencies and Normalization: Functional dependencies, Decomposition, Full
Functional Dependency (FFD), Transitive Dependency (TD), Join Dependency (JD), Multi-valued
Dependency (MVD), Normal Forms (1NF, 2NF, 3NF, BCNF), De-normalization.
Database Security: Introduction, Threats, Counter Measures.
Control Structures: Introduction to conditional control, Iterative control and sequential control
statements, Cursors, Views.
University Institute of Engineering (UIE)
Department of Computer Science and Engineering (CSE)
Contents of the Syllabus
48
UNIT-III [10h]
Package, Procedures and Triggers: Parts of procedures, Parameter modes, Advantages of
procedures, Syntax for creating triggers, Types of triggers, package specification and package body,
developing a package, Bodiless package, Advantages of packages.
Transaction Management and Concurrency Control: Introduction to Transaction Processing,
Properties of Transactions, Serializability and Recoverability, Need for Concurrency Control, Locking
Techniques, Time Stamping Methods, Optimistic Techniques and Granularity of Data items.
Database Recovery of database: Introduction, Need for Recovery, Types of errors, Recovery
Techniques.
University Institute of Engineering (UIE)
Department of Computer Science and Engineering (CSE)
49
Chapter 1.2
(Data Models)
Data Models: Relational Model, Network Model, Hierarchical Model, ER Model:
Design, issues, Mapping constraints, ER diagram, Comparison of Models.
University Institute of Engineering (UIE)
Department of Computer Science and Engineering (CSE)
Learning Objective
• Method to organize data required in an application as
relations.
• Importance for an integrated database in organizations.
• Goals of Data Base Management systems (DBMS).
• Entity-Relationship(ER) modeling to develop a
conceptual model of data.
• Structure and organization of DBMS
University Institute of Engineering (UIE)
Department of Computer Science and Engineering (CSE)
Learning Outcome
• Define program-data independence, data models for
database systems, database schema and database
instances.
• Identify the methodology of conceptual modeling
through Entity Relationship model.
• Identify the methodology of logical model.
• Identify the methodology of physical model.
University Institute of Engineering (UIE)
Department of Computer Science and Engineering (CSE)
Entity-Relationship Model..contd
Relationships: Link between different entities of the database is called
relationship.
Mapping Cardinalities
Cardinality defines the number of entities in one entity set, which can be
associated with the number of entities of other set via relationship set.
•Express the number of entities to which another entity can be associated via
a relationship set.
•Most useful in describing binary relationship sets.
University Institute of Engineering (UIE)
Department of Computer Science and Engineering (CSE)
Types of Relationships
One - One Relationship:- (1 – 1)
Each value in the first table could relate with only one record in the
second table.
One – Many Relationship:- (1 - ∞)
Each value in the first table could relate with many records in the second
table.
Many – Many Relationship (∞ - ∞)
Each value in the first table could relate with many records in the second
table and each value of the second table could relate with many records in
the first table.
Many – One Relationship(∞-1)
•More than one entities from entity set A can be associated with at most one
entity of entity set B, however an entity from entity set B can be associated
with more than one entity from entity set A.
University Institute of Engineering (UIE)
Department of Computer Science and Engineering (CSE)
Relationships….contd
One - One Relationship:- (1 – 1)
Each value in the first table could relate with only one record in the
second table.
University Institute of Engineering (UIE)
Department of Computer Science and Engineering (CSE)
Relationships….contd
One – Many Relationship:- (1 - ∞)
Each value in the first table could relate with many records in the second
table.
University Institute of Engineering (UIE)
Department of Computer Science and Engineering (CSE)
Relationships….contd
• Many-to-many − One entity from A can be associated with more than
one entity from B and vice versa
University Institute of Engineering (UIE)
Department of Computer Science and Engineering (CSE)
Relationships….contd
• Many-to-one − More than one entities from entity set A can
be associated with at most one entity of entity set B, however
an entity from entity set B can be associated with more than
one entity from entity set A.
University Institute of Engineering (UIE)
Department of Computer Science and Engineering (CSE)
E-R Diagrams
• ER Diagram stands for Entity Relationship Diagram, also known
as ERD is a diagram that displays the relationship of entity sets
stored in a database. In other words, ER diagrams help to
explain the logical structure of databases. ER diagrams are
created based on three basic concepts: entities, attributes and
relationships.
• ER Diagrams contain different symbols that use rectangles to
represent entities, ovals to define attributes and diamond
shapes to represent relationships.
• At first look, an ER diagram looks very similar to the flowchart.
However, ER Diagram includes many specialized symbols, and
its meanings make this model unique. The purpose of ER
Diagram is to represent the entity framework infrastructure.
University Institute of Engineering (UIE)
Department of Computer Science and Engineering (CSE)
E-R Diagrams Symbols
• Entity Relationship Diagram Symbols & Notations mainly contains
three basic symbols which are rectangle, oval and diamond to
represent relationships between elements, entities and attributes.
There are some sub-elements which are based on main elements in
ERD Diagram. ER Diagram is a visual representation of data that
describes how data is related to each other using different ERD
Symbols and Notations.
• Following are the main components and its symbols in ER
Diagrams:
• Rectangles: This Entity Relationship Diagram symbol represents
entity types
• Ellipses : Symbol represent attributes
• Diamonds: This symbol represents relationship types
• Lines: It links attributes to entity types and entity types with other
relationship types
• Primary key: attributes are underlined
• Double Ellipses: Represent multi-valued attributes
University Institute of Engineering (UIE)
Department of Computer Science and Engineering (CSE)
E-R Diagrams Symbols
University Institute of Engineering (UIE)
Department of Computer Science and Engineering (CSE)
E-R Diagrams
● Rectangles represent entity sets.
● Diamonds represent relationship sets.
● Lines link attributes to entity sets and entity sets to relationship sets.
● Ellipses represent attributes
● Double ellipses represent multivalued attributes.
● Dashed ellipses denote derived attributes.
● Underline indicates primary key attributes (will study later)
University Institute of Engineering (UIE)
Department of Computer Science and Engineering (CSE)
E-R Diagram With Composite,
Multivalued, and Derived Attributes
University Institute of Engineering (UIE)
Department of Computer Science and Engineering (CSE)
Usage of E-R Diagrams
• Helps you to define terms related to entity relationship modeling
• Provide a preview of how all your tables should connect, what fields
are going to be on each table
• Helps to describe entities, attributes, relationships
• ER diagrams are translatable into relational tables which allows you to
build databases quickly
• ER diagrams can be used by database designers as a blueprint for
implementing data in specific software applications
• The database designer gains a better understanding of the
information to be contained in the database with the help of ERP
diagram
• ERD Diagram allows you to communicate with the logical structure of
the database to users
University Institute of Engineering (UIE)
Department of Computer Science and Engineering (CSE)
Design Issues
• Use of entity sets vs. attributes
Choice mainly depends on the structure of the enterprise being modeled,
and on the semantics associated with the attribute in question.
• Use of entity sets vs. relationship sets
Possible guideline is to designate a relationship set to describe an action
that occurs between entities
• Binary versus n-ary relationship sets
Although it is possible to replace any nonbinary (n-ary, for n > 2)
relationship set by a number of distinct binary relationship sets, a n-ary
relationship set shows more clearly that several entities participate in a
single relationship.
• Placement of relationship attributes
University Institute of Engineering (UIE)
Department of Computer Science and Engineering (CSE)
65
Data Models: A Summary
• Each new data model capitalized on the shortcomings of previous models
• Common characteristics:
– Conceptual simplicity without compromising the semantic
completeness of the database
– Represent the real world as closely as possible
– Representation of real-world transformations (behavior) must comply
with consistency and integrity characteristics of any data model
University Institute of Engineering (UIE)
Department of Computer Science and Engineering (CSE)
Data Models: A Summary
University Institute of Engineering (UIE)
Department of Computer Science and Engineering (CSE)
Data Dictionary
It contains information about the data attributes, elements relationship, user
details, security restrictions and integrity constraints.
University Institute of Engineering (UIE)
Department of Computer Science and Engineering (CSE)
Data Definition Language
(DDL)
• ■ Specification notation for defining the database schema
– ★ E.g. create table account ( account-number char(10), balance integer)
• ■ DDL compiler generates a set of tables stored in a data dictionary
• ■ Data dictionary contains metadata (i.e., data about data)
– ★ database schema
– ★ Data storage and definition language
• ✔ language in which the storage structure and access methods used by the database system are specified
• ✔ Usually an extension of the data definition language
University Institute of Engineering (UIE)
Department of Computer Science and Engineering (CSE)
Data Manipulation Language
(DML)
• ■ Language for accessing and manipulating the data organized by the
appropriate data model
– ★ DML also known as query language
• ■ Two classes of languages
– ★ Procedural – user specifies what data is required and how to get
those data
– ★ Nonprocedural – user specifies what data is required without
specifying how to get those data
• ■ SQL is the most widely used query language
University Institute of Engineering (UIE)
Department of Computer Science and Engineering (CSE)
FAQ
1.Define DBMS? List Database system Applications.
2. Discuss Database Administrator’s responsibilities.
3. What do you understand by dimension and attribute?
4. What is a fact & a fact table?
5. List out few common mistakes encountered during Data
Modelling?
6. What do you understand by Data Modelling?
7. Explain your understanding of different data models?
University Institute of Engineering (UIE)
Department of Computer Science and Engineering (CSE)
References
OTHER REFRENCES
• ER Diagram: Entity Relationship Diagram Model | DBMS
Example (guru99.com)
• ER Diagram Representation - Tutorialspoint
• Entity Relationship Diagram - ER Diagram in DBMS
(beginnersbook.com)
• SUGGESTED BOOK REFERENCES
• Ramez Elmasri and Shamkant B. Navathe,“Fundamentals
of Database System”, The Benjamin / Cummings Publishing
Co.
• Korth and Silberschatz Abraham, “Database
SystemConcepts”, McGraw Hall.
• Pratt,”DBMS”, Cengage Learning.
University Institute of Engineering (UIE)
73
Database
Management
System
CO
Number
Title Level
CO1 To perceive the significance and
implementation of a commercial
relational database system (Oracle)
by writing SQL using the system.
Remember
CO2 To understand the relational database
theory, and be able to write
relational algebra expressions for
queries
Understand
CO3 To identify the basic issues of
transaction processing and
concurrency control and find out its
solutions.
Analysis and
application
Course Outcome Will be covered in
this lecture
Department of Computer Scienceand Engineering (CSE)
University Institute of Engineering (UIE)
Department of Computer Science and Engineering (CSE)
Contents of the Syllabus
74
UNIT-I [10h]
Overview of Databases: Database concepts, DBMS, Data Base System Architecture (Three
Level ANSI-SPARC Architecture), Advantages and Disadvantages of DBMS, Data Independence, DBA
and Responsibilities of DBA, Relational Data Structure, Keys, Relations, Attributes, Schema and
Instances, Referential integrity, Entity integrity.
Data Models: Relational Model, Network Model, Hierarchical Model, ER Model: Design,
issues, Mapping constraints, ER diagram, Comparison of Models.
Relational Algebra & Relational Calculus: Introduction, Syntax, Semantics, Additional
operators, Grouping and Ungrouping, Relational comparisons, Tuple Calculus, Domain Calculus,
Calculus Vs Algebra, Computational capabilities.
UNIT-II [10h]
Functional dependencies and Normalization: Functional dependencies, Decomposition, Full
Functional Dependency (FFD), Transitive Dependency (TD), Join Dependency (JD), Multi-valued
Dependency (MVD), Normal Forms (1NF, 2NF, 3NF, BCNF), De-normalization.
Database Security: Introduction, Threats, Counter Measures.
Control Structures: Introduction to conditional control, Iterative control and sequential control
statements, Cursors, Views.
University Institute of Engineering (UIE)
Department of Computer Science and Engineering (CSE)
Contents of the Syllabus
75
UNIT-III [10h]
Package, Procedures and Triggers: Parts of procedures, Parameter modes, Advantages of
procedures, Syntax for creating triggers, Types of triggers, package specification and package body,
developing a package, Bodiless package, Advantages of packages.
Transaction Management and Concurrency Control: Introduction to Transaction Processing,
Properties of Transactions, Serializability and Recoverability, Need for Concurrency Control, Locking
Techniques, Time Stamping Methods, Optimistic Techniques and Granularity of Data items.
Database Recovery of database: Introduction, Need for Recovery, Types of errors, Recovery
Techniques.
University Institute of Engineering (UIE)
Department of Computer Science and Engineering (CSE)
76
Chapter 1.2
(Data Models)
Data Models: Relational Model, Network Model, Hierarchical Model, ER Model:
Design, issues, Mapping constraints, ER diagram, Comparison of Models.
University Institute of Engineering (UIE)
Department of Computer Science and Engineering (CSE)
Learning Objective
• Method to organize data required in an application as
relations.
• Importance for an integrated database in organizations.
• Goals of Data Base Management systems (DBMS).
• Entity-Relationship(ER) modeling to develop a
conceptual model of data.
• Structure and organization of DBMS
University Institute of Engineering (UIE)
Department of Computer Science and Engineering (CSE)
Learning Outcome
• Define program-data independence, data models for
database systems, database schema and database
instances.
• Identify the methodology of conceptual modeling
through Entity Relationship model.
• Identify the methodology of logical model.
• Identify the methodology of physical model.
University Institute of Engineering (UIE)
Department of Computer Science and Engineering (CSE)
Relationship Types
• Specialization
• Generalization
• Aggregation
University Institute of Engineering (UIE)
Department of Computer Science and Engineering (CSE)
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).
University Institute of Engineering (UIE)
Department of Computer Science and Engineering (CSE)
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.
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.
University Institute of Engineering (UIE)
Department of Computer Science and Engineering (CSE)
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).
University Institute of Engineering (UIE)
Comparison of Record based
model
Hierarchical Network Relational
Relationship between
records is of parent child
type.
Relationship between
records is expressed in the
form of pointers or links
Relationship between
records is represented by a
relation that contains a key
for each record involved in
the relatonship.
Many to Many relationship
cannot be expressed in this
model
Many to Many relationship
can be easily implemented.
Many to Many relationship
can also be implemented.
It is simple, straightforward
and natural method of
implementing record
relationships
Record relationship
implementation is very
complex due to the use of
pointers
Relationship
implementation is very easy
through the use of a key or
composite key field
University Institute of Engineering (UIE)
Comparison of Record based
model
Hierarchical Network Relational
This type of model is useful
only when there is some
hierarchical character in the
database
Network model is useful for
representing such records
which have many to many
relationships
Relational model is useful
for representing most of the
real world objects and
relationships among them
In order to represent links
among records, pointers are
used. Thus relations among
records are physical
In network model also the
record relations are physical
Relational model does not
maintain physical
connection among record.
Data is organized logically in
the form of rows and
columns, and stored in
table.
Searching for record is very
difficult since one can
retrieve a child only after
going through its parent
record
Searching a record is easy
since there are multiple
access paths to a data
elements.
A unique indexed key field Is
used to search for a data
element.
University Institute of Engineering (UIE)
Department of Computer Science and Engineering (CSE)
85
Data Models: A Summary
• Each new data model capitalized on the shortcomings of previous models
• Common characteristics:
– Conceptual simplicity without compromising the semantic
completeness of the database
– Represent the real world as closely as possible
– Representation of real-world transformations (behavior) must comply
with consistency and integrity characteristics of any data model
University Institute of Engineering (UIE)
Department of Computer Science and Engineering (CSE)
Data Models: A Summary
University Institute of Engineering (UIE)
Department of Computer Science and Engineering (CSE)
Data Dictionary
It contains information about the data attributes, elements relationship, user
details, security restrictions and integrity constraints.
University Institute of Engineering (UIE)
Department of Computer Science and Engineering (CSE)
Data Definition Language
(DDL)
• ■ Specification notation for defining the database schema
– ★ E.g. create table account ( account-number char(10), balance integer)
• ■ DDL compiler generates a set of tables stored in a data dictionary
• ■ Data dictionary contains metadata (i.e., data about data)
– ★ database schema
– ★ Data storage and definition language
• ✔ language in which the storage structure and access methods used by the database system are specified
• ✔ Usually an extension of the data definition language
University Institute of Engineering (UIE)
Department of Computer Science and Engineering (CSE)
Data Manipulation Language
(DML)
• ■ Language for accessing and manipulating the data organized by the
appropriate data model
– ★ DML also known as query language
• ■ Two classes of languages
– ★ Procedural – user specifies what data is required and how to get
those data
– ★ Nonprocedural – user specifies what data is required without
specifying how to get those data
• ■ SQL is the most widely used query language
University Institute of Engineering (UIE)
Department of Computer Science and Engineering (CSE)
SQL COMPONENTS
SQL consists of three components:
1. Data Definition Language (DDL)
2. Data Manipulation Language (DML)
3. Data Control Language (DCL)
University Institute of Engineering (UIE)
Department of Computer Science and Engineering (CSE)
DATA DEFINITION LANGUAGE (DDL)
This component of the SQL language is used to create and modify tables and
other objects in the database. For tables there are three main commands:
CREATE TABLE tablename  to create a table in the database
DROP TABLE tablename  to remove a table from the database
ALTER TABLE tablename  to add or remove columns from a table in the
database
RENAME <new table name> to <old table name>;  To change the name
of a table as per the user’s wish or requirement.
TRUNCATE TABLE<table name>;  Truncate Tables empties the table
completely. Once the data deleted cannot be retrieved.
DESC tablename  To view just the blank table
University Institute of Engineering (UIE)
Department of Computer Science and Engineering (CSE)
CREATE TABLE COMMAND
Purpose:- Tables are the basic unit of data storage in an Oracle
Database. Data is stored in rows and columns.
Syntax:- Create table <TableName> (<ColumnName1> <Data Type>(<Size>),
<ColumnName2> <Data Type>(<Size>), ………..<ColumnName n> <Data
Type>(<Size>));
Example:-
Create table STUDENT (Roll_no number(5), Name varchar2(20), Branch
varchar2(10));
University Institute of Engineering (UIE)
Department of Computer Science and Engineering (CSE)
ALTER TABLE COMMAND
Purpose:- The structure of a table can be modified by using a alter table
command. Alter Table allows changing the structure of an existing table. With
Alter Table it is possible to add or delete columns, create or destroy indexes,
change the data type of existing columns, or rename columns or the table itself
Syntax:-
Adding New Columns
Alter table <table name> add(<new col name> <data type> (<Size>), <new col
name> <data type> (<Size>),…..);
Modifying Existing Column
Alter table <table name> modify(<col name> <new data type> (< new Size>),
<col name> <new data type> (<new Size>),…..);
Dropping A Column
Alter table <table name> drop column <col name>;
University Institute of Engineering (UIE)
Department of Computer Science and Engineering (CSE)
Example:-
Alter table STUDENT add( Telephone number(10));
Alter table STUDENT modify( Telephone number(20));
Alter table STUDENT drop column Telephone;
University Institute of Engineering (UIE)
Department of Computer Science and Engineering (CSE)
RENAME TABLE COMMAND
Purpose:- To change the name of a table as per the user’s wish or
requirement.
Syntax:- Rename <new table name> to <old table name>;
Example:- Rename STUDENT to group_a101;
University Institute of Engineering (UIE)
Department of Computer Science and Engineering (CSE)
DROP TABLE COMMAND
Purpose:- Sometimes table in the database becomes obsolete and need to be
discarded, so we use drop table command.
Syntax:- Drop table <table name>;
Example:-
Drop table CSEA_Data101;
University Institute of Engineering (UIE)
Department of Computer Science and Engineering (CSE)
DATA MANIPULATION LANGUAGE (DML)
DML component of the SQL language is used to manipulate data within a
table. There are four main commands:
SELECT  to select rows of data from a table
INSERT  to insert rows of data into a table
UPDATE  to change rows of data in a table
DELETE  to remove rows of data from a table
University Institute of Engineering (UIE)
Department of Computer Science and Engineering (CSE)
INSERT COMMAND
Command:- Insert data into a table
Purpose:- The Insert Into Table command is used to load the created table
with data to be manipulated later.
Syntax:- Insert into <table name>(<col1>,<col2>,……..,<col n>) values
(<expression1>, <expression2> ,……,<expression3>);
Example:-
Insert into STUDENT values(101, ‘Aanchal’, ’CSE’);
Insert into STUDENT values(126, ‘Jotnain’, ’CSE’);
Insert into STUDENT values(149, ‘Sapanpreet’, ’ECE’);
Insert into STUDENT values(151, ‘Savita’, ’CSE’);
University Institute of Engineering (UIE)
Department of Computer Science and Engineering (CSE)
INSERT DATA INTO A TABLE FROM A TABLE
(Copying contents of a table to another table)
Command:- Insert into….Select
Purpose:- To filter the data that is not required
Syntax:- Insert into <table name>Select <col name1>, <col name2>….
from <table name>;
Example:-
Insert into CSEA_Data101 Select roll_no,name from STUDENT where
roll_no=149;
University Institute of Engineering (UIE)
Department of Computer Science and Engineering (CSE)
SELECT COMMAND
Command:- (a) Selecting all rows and all columns
Purpose:- This command is used to view all the rows and columns of the
table created in the database.
Syntax:- Select * from <table name>;
Example:-
Select * from STUDENT;
University Institute of Engineering (UIE)
Department of Computer Science and Engineering (CSE)
SELECT COMMAND
(b) Selected rows and all columns using where clause
Purpose:- If the information of a particular student is to be retrieved from a
table, its retrieval must be based on a specific condition
Syntax:- Select * from <table name> where <condition>;
Example:-
Select * from STUDENT where roll_no=151;
University Institute of Engineering (UIE)
Department of Computer Science and Engineering (CSE)
ALIAS
Purpose:- SQL aliases are used to give a table, or a column in a table, a
temporary name.
ALIAS COLUMN SYNTAX
Syntax:- SELECT column_name AS alias_name
FROM table_name;
Example:-
SELECT CustomerID AS ID, CustomerName AS Customer
FROM Customers;
University Institute of Engineering (UIE)
Department of Computer Science and Engineering (CSE)
ALIAS TABLE SYNTAX
Syntax:- SELECT column_name(s) FROM table_name AS alias_name;
Example:-
SELECT o.OrderID, o.OrderDate, c.CustomerName
FROM Customers AS c, Orders AS o
WHERE c.CustomerName='Around the
Horn' AND c.CustomerID=o.CustomerID;
University Institute of Engineering (UIE)
Department of Computer Science and Engineering (CSE)
DELETE COMMAND
Purpose:- To delete the rows from the table that satisfies the condition
provided by its where clause and returns the number of records deleted.
Syntax:- Removal of all rows
Delete from <table name>;
Removal of Specific Row(s)
Delete from <table name> where <condition>;
Example:-
Delete from CSEA_Data101 where rollno=149;
Delete from CSEA_Data101;
University Institute of Engineering (UIE)
Department of Computer Science and Engineering (CSE)
DELETE & TRUNCATE
TRUNCATE
 TRUNCATE is a DDL command
 TRUNCATE is executed using a table lock and the whole table is locked to remove all
records.
 We cannot use the WHERE clause with TRUNCATE.
 TRUNCATE removes all rows from a table.
 Minimal logging in the transaction log, so it is faster performance-wise.
DELETE
 DELETE is a DML command.
 DELETE is executed using a row lock, each row in the table is locked for deletion.
 We can use where clause with DELETE to filter & delete specific records.
 The DELETE command is used to remove rows from a table based on WHERE
condition.
 It maintains the log, so it slower than TRUNCATE.
University Institute of Engineering (UIE)
Department of Computer Science and Engineering (CSE)
DROP COMMAND
1. The DROP command removes a table from the
database.
2. All the tables' rows, indexes, and privileges will also
be removed.
3. No DML triggers will be fired.
4. The operation cannot be rolled back.
5. DROP and TRUNCATE are DDL commands, whereas
DELETE is a DML command.
6. DELETE operations can be rolled back (undone),
while DROP and TRUNCATE operations cannot be
rolled back
University Institute of Engineering (UIE)
Department of Computer Science and Engineering (CSE)
Difference between DELETE, DROP and TRUNCATE
DELETE DROP TRUNCATE
1. It is a DML command. 1. It is a DDL command. 1. It is a DDL command.
2. It is used to delete rows or records
based on conditions specified in the
WHERE clause.
2. It is used to delete the entire table
along with its schema and structure
respectively.
2. It is used to delete the entire
records of a table without affecting
the schema of the table.
3. If the WHERE clause is not specified
with conditions it deletes all the
records of the table.
3. There is no WHERE clause. 3. There is no WHERE clause.
4. It is a DML command. As a result,
the operation can be rolled back.
4. It is a DDL command. As a result,
the changes cannot be rolled back or
undone.
4. It is a DDL command. As a result,
the changes cannot be rolled back or
undone.
5. It scans every row before deleting
making it slower and time-consuming.
5. It is faster and time-saving.
5. It is faster than DELETE in execution
because it does not scan every row
before deleting which makes it the
least time-consuming.
6. Syntax: DELETE FROM TABLE
Table_Name WHERE [CONDITIONS];
6. Syntax: DROP TABLE Table_Name;
6. Syntax: TRUNCATE
TABLE Table_Name;
University Institute of Engineering (UIE)
Department of Computer Science and Engineering (CSE)
UPDATE COMMAND
Purpose:- The Update statement updates columns in the existing table’s
rows with new values. The Set clause indicates which column data should be
modified and the new valued they should hold.
Syntax:-
Updating Specific Records
Update <table name> set <col name1>=<expression1>, <col
name2>=<expression2> where <condition>;
Updating All The Records
Update <table name> set <col name1>=<expression1>, <col
name2>=<expression2>;
Example:-
Update STUDENT set Branch=’ECE’ where roll_no=101;
Update STUDENT set Branch=’CSE’;
University Institute of Engineering (UIE)
Department of Computer Science and Engineering (CSE)
DATA CONTROL LANGUAGE (DCL)
This component of the SQL language is used to create privileges to allow
users access to, and manipulation of, the database. There are two main
commands:
GRANT  to grant a privilege to a user
REVOKE  to revoke (remove) a privilege from a user.
University Institute of Engineering (UIE)
Department of Computer Science and Engineering (CSE)
FAQ
1.Define DBMS? List Database system Applications.
2. Discuss Database Administrator’s responsibilities.
3. What do you understand by dimension and attribute?
4. What is a fact & a fact table?
5. List out few common mistakes encountered during Data
Modelling?
6. What do you understand by Data Modelling?
7. Explain your understanding of different data models?
University Institute of Engineering (UIE)
Department of Computer Science and Engineering (CSE)
References
• OTHER REFRENCES
• ER Diagram: Entity Relationship Diagram Model | DBMS Example (guru99.com)
• ER Diagram Representation - Tutorialspoint
• Entity Relationship Diagram - ER Diagram in DBMS (beginnersbook.com)
• http://nptel.ac.in/courses/Webcourse-contents/IISc-
BANG/notused/IISc/New%20Rajaram%20pdfs/module8.pdf
• http://ecomputernotes.com/fundamental/what-is-a-database/type-of-data-models
• https://beginnersbook.com/2015/04/data-models-in-dbms/
• http://www.odbms.org/wp-
content/uploads/2013/11/Data_Modeling_ConcepttoDBMS.pdf
SUGGESTED BOOK REFERENCES
• Ramez Elmasri and Shamkant B. Navathe,“Fundamentals of Database System”, The Benjamin / Cummings Publishing Co.
• Korth and Silberschatz Abraham, “Database SystemConcepts”, McGraw Hall.
• Pratt,”DBMS”, Cengage Learning.
University Institute of Engineering (UIE)
113
Database
Management
System
CO
Number
Title Level
CO1 To perceive the significance and
implementation of a commercial
relational database system (Oracle)
by writing SQL using the system.
Remember
CO2 To understand the relational database
theory, and be able to write
relational algebra expressions for
queries
Understand
CO3 To identify the basic issues of
transaction processing and
concurrency control and find out its
solutions.
Analysis and
application
Course Outcome Will be covered in
this lecture
Department of Computer Science and Engineering (CSE)
University Institute of Engineering (UIE)
Department of Computer Science and Engineering (CSE)
Contents of the Syllabus
114
UNIT-I [10h]
Overview of Databases: Database concepts, DBMS, Data Base System Architecture (Three
Level ANSI-SPARC Architecture), Advantages and Disadvantages of DBMS, Data Independence, DBA
and Responsibilities of DBA, Relational Data Structure, Keys, Relations, Attributes, Schema and
Instances, Referential integrity, Entity integrity.
Data Models: Relational Model, Network Model, Hierarchical Model, ER Model: Design,
issues, Mapping constraints, ER diagram, Comparison of Models.
Relational Algebra & Relational Calculus: Introduction, Syntax, Semantics, Additional
operators, Grouping and Ungrouping, Relational comparisons, Tuple Calculus, Domain Calculus,
Calculus Vs Algebra, Computational capabilities.
UNIT-II [10h]
Functional dependencies and Normalization: Functional dependencies, Decomposition, Full
Functional Dependency (FFD), Transitive Dependency (TD), Join Dependency (JD), Multi-valued
Dependency (MVD), Normal Forms (1NF, 2NF, 3NF, BCNF), De-normalization.
Database Security: Introduction, Threats, Counter Measures.
Control Structures: Introduction to conditional control, Iterative control and sequential control
statements, Cursors, Views.
Department of Computer Science and Engineering (CSE)
University Institute of Engineering (UIE)
Department of Computer Science and Engineering (CSE)
Contents of the Syllabus
115
UNIT-III [10h]
Package, Procedures and Triggers: Parts of procedures, Parameter modes, Advantages of
procedures, Syntax for creating triggers, Types of triggers, package specification and package body,
developing a package, Bodiless package, Advantages of packages.
Transaction Management and Concurrency Control: Introduction to Transaction Processing,
Properties of Transactions, Serializability and Recoverability, Need for Concurrency Control, Locking
Techniques, Time Stamping Methods, Optimistic Techniques and Granularity of Data items.
Database Recovery of database: Introduction, Need for Recovery, Types of errors, Recovery
Techniques.
Department of Computer Science and Engineering (CSE)
University Institute of Engineering (UIE)
Department of Computer Science and Engineering (CSE)
116
Chapter 1.3
(Relational Algebra & Relational Calculus)
Relational Algebra & Relational Calculus: Introduction, Syntax, Semantics, Additional
operators, Grouping and Ungrouping, Relational comparisons, Tuple Calculus, Domain
Calculus, Calculus vs Algebra, Computational capabilities.
University Institute of Engineering (UIE)
Department of Computer Science and Engineering (CSE)
Learning Objective
• To study relational algebra concepts, selection ,projection
,relational calculus which helps in understanding queries
• Fundamentals operations on Relational Algebra
• Tuple and Domain Relational Calculus
University Institute of Engineering (UIE)
Department of Computer Science and Engineering (CSE)
Learning Outcome
• Apply relational database theory, and be able to write
relational algebra expressions for queries
• Utilize the knowledge of basics of SQL and construct
queries using SQL
• Understanding relational algebra operators including
extended operators
University Institute of Engineering (UIE)
Department of Computer Science and Engineering (CSE)
Introduction
• Relational algebra
– Basic set of operations for the relational model
– More operational (procedural), very useful for representing
execution plans.
• Relational calculus
– Higher-level declarative language for specifying relational queries
– Lets users describe what they want, rather than how to compute
it: Non-operational, declarative.
University Institute of Engineering (UIE)
Department of Computer Science and Engineering (CSE)
Relational Algebra
• Relational algebra operations work on one or more relations to define
another relation without changing the original relations.
• Both operands and results are relations, so output from one operation
can become input to another operation.
• Allows expressions to be nested, just as in arithmetic. This property is
called closure.
• Five basic operations in relational algebra: Selection, Projection,
Cartesian product, Union and Set Difference.
• These perform most of the data retrieval operations needed.
• Also have Join, Intersection, and Division operations, which can be
expressed in terms of 5 basic operations.
University Institute of Engineering (UIE)
Department of Computer Science and Engineering (CSE)
Relational Algebra
• Basic operations:
– Selection ( ) Selects a subset of rows from relation.
– Projection ( ) Deletes unwanted columns from relation.
– Cross-product ( ) Allows us to combine two relations.
– Set-difference ( ) Tuples in reln. 1, but not in reln. 2.
– Union ( ) Tuples in reln. 1 and in reln. 2.
• Additional operations:
– Intersection, join, division, renaming: Not essential, but (very!) useful.
University Institute of Engineering (UIE)
Department of Computer Science and Engineering (CSE)
Relational Algebra Operations
University Institute of Engineering (UIE)
Department of Computer Science and Engineering (CSE)
Relational Algebra Operations
University Institute of Engineering (UIE)
Department of Computer Science and Engineering (CSE)
124
Selection (or Restriction)
• σpredicate (R)
– Works on a single relation R and defines a relation that contains only
those tuples (rows) of R that satisfy the specified condition (predicate).
– Selects rows that satisfy selection condition.
– No duplicates in result!
– Schema of result identical to schema of input relation.
– Selection is distributive over binary operators
– Selection is commutative
University Institute of Engineering (UIE)
Department of Computer Science and Engineering (CSE)
Example - Selection Restriction)
• List all staff with a salary greater than £10,000.
σsalary > 10000 (Staff)
University Institute of Engineering (UIE)
Department of Computer Science and Engineering (CSE)
Projection
• Πcol1, . . . , coln(R)
– Works on a single relation R and defines a relation that contains a
vertical subset of R, extracting the values of specified attributes and
eliminating duplicates.
– Deletes attributes that are not in projection list.
– Schema of result contains exactly the fields in the projection list,
with the same names that they had in the input relation.
– Projection operator has to eliminate duplicates!
Note: real systems typically don’t do duplicate elimination unless the
user explicitly asks for it (by DISTINCT). Why not?
University Institute of Engineering (UIE)
Department of Computer Science and Engineering (CSE)
Example - Projection
• Produce a list of salaries for all staff, showing only staffNo, fName,
lName, and salary details.
ΠstaffNo, fName, lName, salary(Staff)
University Institute of Engineering (UIE)
Department of Computer Science and Engineering (CSE)
Union
• R ∪ S
– Union of two relations R and S defines a relation that contains all the
tuples of R, or S, or both R and S,
duplicate tuples being eliminated.
– R and S must be union-compatible.
• If R and S have I and J tuples, respectively, union is obtained by
concatenating them into one relation with a maximum of (I + J) tuples.
University Institute of Engineering (UIE)
Department of Computer Science and Engineering (CSE)
Example - UNION
• List all cities where there is either a branch office or a property for rent.
Πcity(Branch) ∪ Πcity(PropertyForRent)
University Institute of Engineering (UIE)
Department of Computer Science and Engineering (CSE)
Set Difference
• R – S
– Defines a relation consisting of the tuples that are in relation R,
but not in S.
– R and S must be union-compatible.
University Institute of Engineering (UIE)
Department of Computer Science and Engineering (CSE)
Example - Set Difference
• List all cities where there is a branch office but no properties for rent.
Πcity(Branch) – Πcity(PropertyForRent)
University Institute of Engineering (UIE)
Department of Computer Science and Engineering (CSE)
Intersection
• R ∩ S
– Defines a relation consisting of the set of all tuples that are in both R
and S.
– R and S must be union-compatible.
• Expressed using basic operations:
R ∩ S = R – (R – S)
University Institute of Engineering (UIE)
Department of Computer Science and Engineering (CSE)
Example - Intersection
• List all cities where there is both a branch office and at least one property
for rent.
Πcity(Branch) ∩ Πcity(PropertyForRent)
University Institute of Engineering (UIE)
Department of Computer Science and Engineering (CSE)
Cartesian product
• R X S
– Defines a relation that is the concatenation of every tuple of
relation “R with every tuple of relation S”
University Institute of Engineering (UIE)
Department of Computer Science and Engineering (CSE)
135
Example - Cartesian product
• List the names and comments of all clients who have viewed a property for
rent.
(ΠclientNo, fName, lName(Client)) X (ΠclientNo, propertyNo, comment (Viewing))
Pearson Education © 2009
University Institute of Engineering (UIE)
Department of Computer Science and Engineering (CSE)
136
Example - Cartesian product and
Selection
• Use selection operation to extract those tuples where Client.clientNo =
Viewing.clientNo.
sClient.clientNo = Viewing.clientNo((ÕclientNo, fName, lName(Client)) Χ (ÕclientNo,
propertyNo, comment(Viewing)))
● Cartesian product and Selection can be reduced to a single operation called a Join.
Pearson Education © 2009
University Institute of Engineering (UIE)
Department of Computer Science and Engineering (CSE)
137
Join Operations
• JOINs can be used to combine tables
• Join is a derivative of Cartesian product.
• Equivalent to performing a Selection, using join predicate as selection
formula, over Cartesian product of the two operand relations.
• One of the most difficult operations to implement efficiently in an
RDBMS and one reason why RDBMSs have intrinsic performance
problems.
Pearson Education © 2009
University Institute of Engineering (UIE)
Department of Computer Science and Engineering (CSE)
138
Join Operations
• Various forms of join operation
– JOIN (Inner Join) : Return rows when there is at least one match
in both tables
– LEFT JOIN(Left Outer Join): Return all rows from the left
table, even if there are no matches in the right table
– RIGHT JOIN(Right Outer Join): Return all rows from the right
table, even if there are no matches in the left table
– FULL JOIN: Return rows when there is a match in one of the
tables
Pearson Education © 2009
University Institute of Engineering (UIE)
Department of Computer Science and Engineering (CSE)
SQL INNER JOIN Syntax
SELECT column_name(s) FROM table_name1 INNER JOIN table_name2
ON
table_name1.column_name=table_name2.column_name
INNER JOIN is the same as JOIN
The word "INNER" is optional
University Institute of Engineering (UIE)
Department of Computer Science and Engineering (CSE)
*
Example - Inner Join
University Institute of Engineering (UIE)
Department of Computer Science and Engineering (CSE)
Left Join
University Institute of Engineering (UIE)
Department of Computer Science and Engineering (CSE)
Example - Left Join
University Institute of Engineering (UIE)
Department of Computer Science and Engineering (CSE)
Right Join
University Institute of Engineering (UIE)
Department of Computer Science and Engineering (CSE)
Example – Right Join
University Institute of Engineering (UIE)
Department of Computer Science and Engineering (CSE)
Full Join
University Institute of Engineering (UIE)
Department of Computer Science and Engineering (CSE)
Example – Full Join
University Institute of Engineering (UIE)
Department of Computer Science and Engineering (CSE)
FAQ
1. How does Tuple-oriented relational calculus differ from domain-
oriented relational calculus?
2. Define Relational Algebra and Relational Calculus
3. What is degree of a Relation?
4. What is a Relation Schema and a Relation?
5. List various Operators used in Relational Algebra and Calculus
6. Solve the given by relational algebra. The Relations are :
• Emp(empno,ename,sal,job,comm,deptno)
• Dept (deptno,dname,dloc)
• Create a query to list unique jobs that are in deptno 30 and include the
location of department 30 in output
University Institute of Engineering (UIE)
Department of Computer Science and Engineering (CSE)
References
OTHER REFRENCES
• https://cs.uwaterloo.ca/~tozsu/courses/CS348/notes/4b-calculus-handout-notes.pdf
• http://www.ccs.neu.edu/home/kathleen/classes/cs3200/4-RAAndRC.pdf
• https://www2.cs.sfu.ca/CourseCentral/354/louie/Chap3_practice.pdf
• http://www.nyu.edu/classes/jcf/CSCI-GA.2433-
001_fa11/slides/session5/RelationalAlgebra-RelationalCalculus-SQL.pdf
• https://blog.inf.ed.ac.uk/da15/files/2015/01/inf1-da-15-t3.pdf
• DatabaseSystemConceptsbySudarshan,Korth(McGraw-HillEducation)
• FundamentalsofDatabaseSystemByElmasari&Navathe-PearsonEducation
• http://ecomputernotes.com/database-system/rdbms
• https://www.tutorialspoint.com/sql/sql-rdbms-concepts.htm
• https://www.studytonight.com/dbms/rdbms-concept
SUGGESTED BOOK REFERENCES
• Ramez Elmasri and Shamkant B. Navathe,“Fundamentals of Database System”, The
Benjamin / Cummings Publishing Co.
• Korth and Silberschatz Abraham, “Database SystemConcepts”, McGraw Hall.
• Pratt,”DBMS”, Cengage Learning.
University Institute of Engineering (UIE)
150
Database
Management
System
CO
Number
Title Level
CO1 To perceive the significance and
implementation of a commercial
relational database system (Oracle)
by writing SQL using the system.
Remember
CO2 To understand the relational database
theory, and be able to write
relational algebra expressions for
queries
Understand
CO3 To identify the basic issues of
transaction processing and
concurrency control and find out its
solutions.
Analysis and
application
Course Outcome Will be covered in
this lecture
Department of Computer Science and Engineering (CSE)
University Institute of Engineering (UIE)
Department of Computer Science and Engineering (CSE)
Contents of the Syllabus
151
UNIT-I [10h]
Overview of Databases: Database concepts, DBMS, Data Base System Architecture (Three
Level ANSI-SPARC Architecture), Advantages and Disadvantages of DBMS, Data Independence, DBA
and Responsibilities of DBA, Relational Data Structure, Keys, Relations, Attributes, Schema and
Instances, Referential integrity, Entity integrity.
Data Models: Relational Model, Network Model, Hierarchical Model, ER Model: Design,
issues, Mapping constraints, ER diagram, Comparison of Models.
Relational Algebra & Relational Calculus: Introduction, Syntax, Semantics, Additional
operators, Grouping and Ungrouping, Relational comparisons, Tuple Calculus, Domain Calculus,
Calculus Vs Algebra, Computational capabilities.
UNIT-II [10h]
Functional dependencies and Normalization: Functional dependencies, Decomposition, Full
Functional Dependency (FFD), Transitive Dependency (TD), Join Dependency (JD), Multi-valued
Dependency (MVD), Normal Forms (1NF, 2NF, 3NF, BCNF), De-normalization.
Database Security: Introduction, Threats, Counter Measures.
Control Structures: Introduction to conditional control, Iterative control and sequential control
statements, Cursors, Views.
Department of Computer Science and Engineering (CSE)
University Institute of Engineering (UIE)
Department of Computer Science and Engineering (CSE)
Contents of the Syllabus
152
UNIT-III [10h]
Package, Procedures and Triggers: Parts of procedures, Parameter modes, Advantages of
procedures, Syntax for creating triggers, Types of triggers, package specification and package body,
developing a package, Bodiless package, Advantages of packages.
Transaction Management and Concurrency Control: Introduction to Transaction Processing,
Properties of Transactions, Serializability and Recoverability, Need for Concurrency Control, Locking
Techniques, Time Stamping Methods, Optimistic Techniques and Granularity of Data items.
Database Recovery of database: Introduction, Need for Recovery, Types of errors, Recovery
Techniques.
Department of Computer Science and Engineering (CSE)
University Institute of Engineering (UIE)
Department of Computer Science and Engineering (CSE)
153
Chapter 3
(Relational Algebra & Relational Calculus)
Relational Algebra & Relational Calculus: Introduction, Syntax, Semantics, Additional
operators, Grouping and Ungrouping, Relational comparisons, Tuple Calculus, Domain
Calculus, Calculus vs Algebra, Computational capabilities.
University Institute of Engineering (UIE)
Department of Computer Science and Engineering (CSE)
Learning Objective
• To study relational algebra concepts, selection ,projection
,relational calculus which helps in understanding queries
• Fundamentals operations on Relational Algebra
• Tuple and Domain Relational Calculus
University Institute of Engineering (UIE)
Department of Computer Science and Engineering (CSE)
Learning Outcome
• Apply relational database theory, and be able to write
relational algebra expressions for queries
• Utilize the knowledge of basics of SQL and construct
queries using SQL
• Understanding relational algebra operators including
extended operators
University Institute of Engineering (UIE)
Department of Computer Science and Engineering (CSE)
Relational Calculus
• There are two versions of the relational calculus:
– Tuple relational calculus (TRC)
– Domain relational calculus (DRC)
• The calculus is non-procedural (‘declarative’) compared to the relational algebra
• Calculus has variables, constants, comparison ops, logical connectives and
quantifiers.
– TRC: Variables range over (i.e., get bound to) tuples.
– DRC: Variables range over domain elements (= field values).
– Both TRC and DRC are simple subsets of first-order logic.
• Expressions in the calculus are called formulas. An answer tuple is essentially an
assignment of constants to variables that make the formula evaluate to true.
University Institute of Engineering (UIE)
Department of Computer Science and Engineering (CSE)
• Relational Calculus
• Relational Algebra is a PROCEDURAL LANGUAGE
⮚ we must explicitly provide a sequence of operations to
• generate a desired output result
• Relational Calculus is a DECLARATIVE LANGUAGE
⮚ we specify what to retrieve, not how to retrieve it
University Institute of Engineering (UIE)
Department of Computer Science and Engineering (CSE)
What is Relational Calculus?
• It is a formal language based upon predicate calculus
• It allows you to express the set of tuples you want from a
database using a formula
• Expressions in the calculus are called formula
• An answer tuple is essentially an assignment of constants to vari
ables that make the formula evaluate to true.
University Institute of Engineering (UIE)
Department of Computer Science and Engineering (CSE)
Declarative ~ Non-Procedural
Two variants of relational calculus are
• TUPLE Relational Calculus
• Domain Relational Calculus
• Calculus has variables, constants, comparison ops, logical
connectives and quantifiers.
• TRC: Variables range over (i.e., get bound to) tuples.
• DRC: Variables range over domain elements
(= field values)
University Institute of Engineering (UIE)
Department of Computer Science and Engineering (CSE)
RELATIONAL CALCULUS
• If a retrieval can be specified in the relational calculus, it
can be specified in the relational algebra, and vise versa
→expressive power of the languages is identical
• A query language L is Relationally complete if
L can express any query that can be expressed in the
relational calculus
University Institute of Engineering (UIE)
Department of Computer Science and Engineering (CSE)
Relational Calculus
• TRC and DRC are semantically similar
• In TRC, tuples share an equal status as variables, and field referencing
can be used to select tuple parts
• In DRC, formal variables are explicit
University Institute of Engineering (UIE)
Department of Computer Science and Engineering (CSE)
Tuple Relational Calculus
• Query: {T | P(T)}
– T is tuple variable
– P(T) is a formula that describes T
• Result, the set of all tuples t for which P(t) evaluates True.
– Find all sailors with a rating above 7.
–
• Atomic formula
–
– R.a op S.b , op is one of
– R.a op constant
University Institute of Engineering (UIE)
Department of Computer Science and Engineering (CSE)
Tuple Relational Calculus
• A logical language with variables ranging over tuples:
{ T | Cond }
– Return all tuples T that satisfy the condition Cond.
• { T | R(T) }: returns all tuples T such that T is a tuple in relation
R.
• { T.name | F ACULT Y (T) AND T.DeptId = ‘CS’ }.
returns the values of name field of all faculty tuples with the
value ’CS’ in their department id field.
– The variable T is said to be free since it is not bound by a
quantifier (for all, exists).
– The result of this statement is a relation (or a set of tuples) that
correspond to all possible ways to satisfy this statement.
– Find all possible instances of T that make this statement true.
University Institute of Engineering (UIE)
Department of Computer Science and Engineering (CSE)
TUPLE RELATIONAL CALCULUS
• Query: {T|P(T)}
• T is tuple variable
• P(T) is a formula that describes T
Result: the set of all tuples t for which P(t) evaluates Tr
ue.
⮚ Find all sailors with a rating above 7.
University Institute of Engineering (UIE)
Department of Computer Science and Engineering (CSE)
OPERATIONS in Tuple Relational Calculus
• ∧ - AND
• ∨ - OR
• ¬ - NOT
• ∃x – there exists x
• ∀x – for all x
Note: General power of 1st order predicate calculus – allow
more flexible expression formats
University Institute of Engineering (UIE)
Department of Computer Science and Engineering (CSE)
TUPLE RELATIONAL CALCULUS
University Institute of Engineering (UIE)
Department of Computer Science and Engineering (CSE)
TUPLE RELATIONAL CALCULUS
University Institute of Engineering (UIE)
Department of Computer Science and Engineering (CSE)
JOINS IN THE TUPLE RELATIONAL CALCULUS
University Institute of Engineering (UIE)
Department of Computer Science and Engineering (CSE)
Examples
Consider relations for queries:
• Relation 1:
University Institute of Engineering (UIE)
Department of Computer Science and Engineering (CSE)
Relation 2:
Relation
3:
University Institute of Engineering (UIE)
Department of Computer Science and Engineering (CSE)
1. Find the loan number, branch, amount of loans of greater than or equal
to 10000 amount
{t| t ∈ loan ∧ t[amount]>=10000}
2. Find the loan number for each loan of an amount greater or equal to
10000.
{t| ∃ s ∈ loan(t[loan number] = s[loan number] ∧ s[amount]>=10000)}
3. Find the names of all customers who have a loan and an account at the
bank.
{t | ∃ s ∈ borrower( t[customer-name] = s[customer-name]) ∧ ∃ u ∈ depositor(
t[customer-name] = u[customer-name])}
University Institute of Engineering (UIE)
Department of Computer Science and Engineering (CSE)
4. Find the names of all customers having a loan at the
“ABC” branch.
{t | ∃ s ∈ borrower(t[customer-name] = s[customer-name]
∧ ∃ u ∈ loan(u[branch-name] = “ABC” ∧ u[loan-number] =
s[loan-number]))}
University Institute of Engineering (UIE)
Department of Computer Science and Engineering (CSE)
Domain Relational Calculus
• Query has the form:
❖ Answer includes all tuples that
make the formula be true.
Formula is recursively defined, starting with simple atomic formulas
(getting tuples from relations or making comparisons of values), and
building bigger and better formulas using the logical connectives.
University Institute of Engineering (UIE)
Department of Computer Science and Engineering (CSE)
Domain Relational Calculus
University Institute of Engineering (UIE)
Department of Computer Science and Engineering (CSE)
Domain Relational Calculus
• Query has the form:
{ <x1,x2….xn>| p(<x1,x2….xn>)}
• Domain Variable – ranges over the values in the domain of
some attribute or is a constant
• Example: If the domain variable x1 maps to attribute -
Name char(20) then x1 ranges over all strings that are 20
characters long
Not just the strings values in the relation’s attribute
• Answer includes all tuples that make the formula p() true.
University Institute of Engineering (UIE)
Department of Computer Science and Engineering (CSE)
DOMAIN RELATIONAL CALCULUS
University Institute of Engineering (UIE)
Department of Computer Science and Engineering (CSE)
DRC Formulas
• Atomic Formulas
1. <x1,x2,…xn>∈ Relation where Relation is a relation with n attributes
2. X operation Y
3. X operation constant
Where operation is an operator in the set { , = , ≤, ≥, ≠ }
• Recursive definition of a Formula:
1. An atomic formula
2. ¬p, p∧q, p∨q, where p and q are formulas
3. ∃X(p(X)), where variable X is free in p(X)
4. ∀X(p(X)), where variable X is free in p(X)
The use of quantifiers ∃X and ∀X is said to bind X
A variable that is not bound is free.
University Institute of Engineering (UIE)
Department of Computer Science and Engineering (CSE)
Quantifiers: ∀x and ∃x
• Variable x is said to be subordinate to the quantifier
You are restricting (or binding) the value of the variable x
to set S
• The set S is known as the range of the quantifier
• ∀x predicate true for all elements in set S
• ∃x predicate true for at least 1 element in set S
University Institute of Engineering (UIE)
Department of Computer Science and Engineering (CSE)
Examples
1. Find the loan number, branch, amount of loans of greater
than or equal to 100 amount.
{≺l, b, a≻ | ≺l, b, a≻ ∈ loan ∧ (a ≥ 100)}
2. Find the loan number for each loan of an amount greater
or equal to 150.
{≺l≻ | ∃ b, a (≺l, b, a≻ ∈ loan ∧ (a ≥ 150)}
3. Find the names of all customers having a loan at the
“Main” branch and find the loan amount .
{≺c, a≻ | ∃ l (≺c, l≻ ∈ borrower ∧ ∃ b (≺l, b, a≻ ∈ loan
∧ (b = “Main”)))}
University Institute of Engineering (UIE)
Department of Computer Science and Engineering (CSE)
Relational Calculus: Summary
• Relational calculus is non-operational
⮚ Users define queries in terms of what they want, not in
terms of how to compute it. (Declarativeness.)
• Algebra and safe calculus have the same expressive
power, leading to the notion of relational completeness.
• Relational calculus had big influence on the design of SQL
and Query-by-Example
University Institute of Engineering (UIE)
Department of Computer Science and Engineering (CSE)
Summary
• Relational algebra is more operational; useful as internal representation
for query evaluation plans.
• Relational calculus is non-operational, and users define queries in terms
of what they want, not in terms of how to compute it. (Declarativeness.)
• Algebra and safe calculus have same expressive power, leading to the
notion of relational completeness.
University Institute of Engineering (UIE)
Department of Computer Science and Engineering (CSE)
FAQ
1. How does Tuple-oriented relational calculus differ from
domain-oriented relational calculus?
2. Define Relational Algebra and Relational Calculus
3. What is degree of a Relation?
4. What is a Relation Schema and a Relation?
5. List various Operators used in Relational Algebra and
Calculus
University Institute of Engineering (UIE)
Department of Computer Science and Engineering (CSE)
References
OTHER REFRENCES
• https://cs.uwaterloo.ca/~tozsu/courses/CS348/notes/4b-calculus-handout-notes.pdf
• http://www.ccs.neu.edu/home/kathleen/classes/cs3200/4-RAAndRC.pdf
• https://www2.cs.sfu.ca/CourseCentral/354/louie/Chap3_practice.pdf
• http://www.nyu.edu/classes/jcf/CSCI-GA.2433-001_fa11/slides/session5/RelationalAlgebra-
RelationalCalculus-SQL.pdf
• https://blog.inf.ed.ac.uk/da15/files/2015/01/inf1-da-15-t3.pdf
• DatabaseSystemConceptsbySudarshan,Korth(McGraw-HillEducation)
• FundamentalsofDatabaseSystemByElmasari&Navathe-PearsonEducation
• http://ecomputernotes.com/database-system/rdbms
• https://www.tutorialspoint.com/sql/sql-rdbms-concepts.htm
• https://www.studytonight.com/dbms/rdbms-concept
SUGGESTED BOOK REFERENCES
• Ramez Elmasri and Shamkant B. Navathe,“Fundamentals of Database System”, The
Benjamin / Cummings Publishing Co.
• Korth and Silberschatz Abraham, “Database SystemConcepts”, McGraw Hall.
• Pratt,”DBMS”, Cengage Learning.

More Related Content

Similar to PPT Lecture 1.1 and 1.2(Database concepts and database system architecture) (1).pptx

UNIT machine learning unit 1,algorithm pdf
UNIT machine learning  unit 1,algorithm pdfUNIT machine learning  unit 1,algorithm pdf
UNIT machine learning unit 1,algorithm pdf
OmarFarooque9
 
Anshu Joshi_2371050_DBMS.pptxData base management system
Anshu Joshi_2371050_DBMS.pptxData base management systemAnshu Joshi_2371050_DBMS.pptxData base management system
Anshu Joshi_2371050_DBMS.pptxData base management system
anshjoshi7417
 

Similar to PPT Lecture 1.1 and 1.2(Database concepts and database system architecture) (1).pptx (20)

Introduction to RDBMS
Introduction to RDBMSIntroduction to RDBMS
Introduction to RDBMS
 
Intoduction- Database Management System
Intoduction- Database Management SystemIntoduction- Database Management System
Intoduction- Database Management System
 
Database Systems - Lecture Week 1
Database Systems - Lecture Week 1Database Systems - Lecture Week 1
Database Systems - Lecture Week 1
 
UNIT machine learning unit 1,algorithm pdf
UNIT machine learning  unit 1,algorithm pdfUNIT machine learning  unit 1,algorithm pdf
UNIT machine learning unit 1,algorithm pdf
 
Ch 2-introduction to dbms
Ch 2-introduction to dbmsCh 2-introduction to dbms
Ch 2-introduction to dbms
 
database1.pdf
database1.pdfdatabase1.pdf
database1.pdf
 
PURPOSE OF DATABASE final.pptx
PURPOSE OF DATABASE final.pptxPURPOSE OF DATABASE final.pptx
PURPOSE OF DATABASE final.pptx
 
Ch01
Ch01Ch01
Ch01
 
Unit 2 DATABASE ESSENTIALS.pptx
Unit 2 DATABASE ESSENTIALS.pptxUnit 2 DATABASE ESSENTIALS.pptx
Unit 2 DATABASE ESSENTIALS.pptx
 
PHP/MySQL First Session Material
PHP/MySQL First Session MaterialPHP/MySQL First Session Material
PHP/MySQL First Session Material
 
Intro.pptx
Intro.pptxIntro.pptx
Intro.pptx
 
DBMS Bascis
DBMS BascisDBMS Bascis
DBMS Bascis
 
Database part1-
Database part1-Database part1-
Database part1-
 
Database & Database Users
Database & Database UsersDatabase & Database Users
Database & Database Users
 
ESSENTIAL of (CS/IT/IS) class 06 (database)
ESSENTIAL of (CS/IT/IS) class 06 (database)ESSENTIAL of (CS/IT/IS) class 06 (database)
ESSENTIAL of (CS/IT/IS) class 06 (database)
 
Anshu Joshi_2371050_DBMS.pptxData base management system
Anshu Joshi_2371050_DBMS.pptxData base management systemAnshu Joshi_2371050_DBMS.pptxData base management system
Anshu Joshi_2371050_DBMS.pptxData base management system
 
Unit 1 dbms
Unit 1 dbmsUnit 1 dbms
Unit 1 dbms
 
Comp107 chep6
Comp107 chep6Comp107 chep6
Comp107 chep6
 
Adbms 2 types of database
Adbms 2 types of databaseAdbms 2 types of database
Adbms 2 types of database
 
CS3270 - DATABASE SYSTEM - Lecture (1)
CS3270 - DATABASE SYSTEM -  Lecture (1)CS3270 - DATABASE SYSTEM -  Lecture (1)
CS3270 - DATABASE SYSTEM - Lecture (1)
 

Recently uploaded

Performance enhancement of machine learning algorithm for breast cancer diagn...
Performance enhancement of machine learning algorithm for breast cancer diagn...Performance enhancement of machine learning algorithm for breast cancer diagn...
Performance enhancement of machine learning algorithm for breast cancer diagn...
IJECEIAES
 
Seizure stage detection of epileptic seizure using convolutional neural networks
Seizure stage detection of epileptic seizure using convolutional neural networksSeizure stage detection of epileptic seizure using convolutional neural networks
Seizure stage detection of epileptic seizure using convolutional neural networks
IJECEIAES
 
Final DBMS Manual (2).pdf final lab manual
Final DBMS Manual (2).pdf final lab manualFinal DBMS Manual (2).pdf final lab manual
Final DBMS Manual (2).pdf final lab manual
BalamuruganV28
 
Maher Othman Interior Design Portfolio..
Maher Othman Interior Design Portfolio..Maher Othman Interior Design Portfolio..
Maher Othman Interior Design Portfolio..
MaherOthman7
 
Online crime reporting system project.pdf
Online crime reporting system project.pdfOnline crime reporting system project.pdf
Online crime reporting system project.pdf
Kamal Acharya
 

Recently uploaded (20)

"United Nations Park" Site Visit Report.
"United Nations Park" Site  Visit Report."United Nations Park" Site  Visit Report.
"United Nations Park" Site Visit Report.
 
Performance enhancement of machine learning algorithm for breast cancer diagn...
Performance enhancement of machine learning algorithm for breast cancer diagn...Performance enhancement of machine learning algorithm for breast cancer diagn...
Performance enhancement of machine learning algorithm for breast cancer diagn...
 
Seizure stage detection of epileptic seizure using convolutional neural networks
Seizure stage detection of epileptic seizure using convolutional neural networksSeizure stage detection of epileptic seizure using convolutional neural networks
Seizure stage detection of epileptic seizure using convolutional neural networks
 
Software Engineering Practical File Front Pages.pdf
Software Engineering Practical File Front Pages.pdfSoftware Engineering Practical File Front Pages.pdf
Software Engineering Practical File Front Pages.pdf
 
Filters for Electromagnetic Compatibility Applications
Filters for Electromagnetic Compatibility ApplicationsFilters for Electromagnetic Compatibility Applications
Filters for Electromagnetic Compatibility Applications
 
What is Coordinate Measuring Machine? CMM Types, Features, Functions
What is Coordinate Measuring Machine? CMM Types, Features, FunctionsWhat is Coordinate Measuring Machine? CMM Types, Features, Functions
What is Coordinate Measuring Machine? CMM Types, Features, Functions
 
Lab Manual Arduino UNO Microcontrollar.docx
Lab Manual Arduino UNO Microcontrollar.docxLab Manual Arduino UNO Microcontrollar.docx
Lab Manual Arduino UNO Microcontrollar.docx
 
Diploma Engineering Drawing Qp-2024 Ece .pdf
Diploma Engineering Drawing Qp-2024 Ece .pdfDiploma Engineering Drawing Qp-2024 Ece .pdf
Diploma Engineering Drawing Qp-2024 Ece .pdf
 
Final DBMS Manual (2).pdf final lab manual
Final DBMS Manual (2).pdf final lab manualFinal DBMS Manual (2).pdf final lab manual
Final DBMS Manual (2).pdf final lab manual
 
Worksharing and 3D Modeling with Revit.pptx
Worksharing and 3D Modeling with Revit.pptxWorksharing and 3D Modeling with Revit.pptx
Worksharing and 3D Modeling with Revit.pptx
 
Maher Othman Interior Design Portfolio..
Maher Othman Interior Design Portfolio..Maher Othman Interior Design Portfolio..
Maher Othman Interior Design Portfolio..
 
Passive Air Cooling System and Solar Water Heater.ppt
Passive Air Cooling System and Solar Water Heater.pptPassive Air Cooling System and Solar Water Heater.ppt
Passive Air Cooling System and Solar Water Heater.ppt
 
Linux Systems Programming: Semaphores, Shared Memory, and Message Queues
Linux Systems Programming: Semaphores, Shared Memory, and Message QueuesLinux Systems Programming: Semaphores, Shared Memory, and Message Queues
Linux Systems Programming: Semaphores, Shared Memory, and Message Queues
 
Autodesk Construction Cloud (Autodesk Build).pptx
Autodesk Construction Cloud (Autodesk Build).pptxAutodesk Construction Cloud (Autodesk Build).pptx
Autodesk Construction Cloud (Autodesk Build).pptx
 
CLOUD COMPUTING SERVICES - Cloud Reference Modal
CLOUD COMPUTING SERVICES - Cloud Reference ModalCLOUD COMPUTING SERVICES - Cloud Reference Modal
CLOUD COMPUTING SERVICES - Cloud Reference Modal
 
8th International Conference on Soft Computing, Mathematics and Control (SMC ...
8th International Conference on Soft Computing, Mathematics and Control (SMC ...8th International Conference on Soft Computing, Mathematics and Control (SMC ...
8th International Conference on Soft Computing, Mathematics and Control (SMC ...
 
Online crime reporting system project.pdf
Online crime reporting system project.pdfOnline crime reporting system project.pdf
Online crime reporting system project.pdf
 
NEWLETTER FRANCE HELICES/ SDS SURFACE DRIVES - MAY 2024
NEWLETTER FRANCE HELICES/ SDS SURFACE DRIVES - MAY 2024NEWLETTER FRANCE HELICES/ SDS SURFACE DRIVES - MAY 2024
NEWLETTER FRANCE HELICES/ SDS SURFACE DRIVES - MAY 2024
 
Module-III Varried Flow.pptx GVF Definition, Water Surface Profile Dynamic Eq...
Module-III Varried Flow.pptx GVF Definition, Water Surface Profile Dynamic Eq...Module-III Varried Flow.pptx GVF Definition, Water Surface Profile Dynamic Eq...
Module-III Varried Flow.pptx GVF Definition, Water Surface Profile Dynamic Eq...
 
UNIT 4 PTRP final Convergence in probability.pptx
UNIT 4 PTRP final Convergence in probability.pptxUNIT 4 PTRP final Convergence in probability.pptx
UNIT 4 PTRP final Convergence in probability.pptx
 

PPT Lecture 1.1 and 1.2(Database concepts and database system architecture) (1).pptx

  • 1. 2 Course Outcome Will be covered in this lecture Department of Computer Science and Engineering (CSE) CO1: To make student learn all core subjects of respective engineering background
  • 2. Contents of the Syllabus 3 Department of Computer Science and Engineering (CSE) Unit-1 Data Base Management Systems Contact Hours:4 CHAPTER 1.1 Introduction and applications of DBMS, Purpose of data base, Data, Independence, Database System architecture- levels. CHAPTER 1.2 Structure of relational databases, Domains, Relations, Relational algebra – fundamental operators and syntax, relational algebra queries, tuple relational calculus. CHAPTER 1.3 Basic concepts, Design process, constraints, Keys, Design issues, E-R diagrams, weak entity sets, extended E-R features – generalization, specialization, aggregation, reduction to E-R database schema CHAPTER 1.4 Functional Dependency – definition, trivial and non-trivial FD, closure of FD set, closure of attributes, irreducible set of FD, Normalization – 1Nf, 2NF, 3NF, Decomposition using FD- dependency preservation, BCNF, Multi- valued dependency, 4NF, Join dependency and 5NF Contact Hours:4
  • 3. Contents of the Syllabus 4 Department of Computer Science and Engineering (CSE) Unit-2 Structured Query Language Contact Hours:4 CHAPTER 2.1 Basics of SQL, DDL, DML, DCL, structure – creation, alteration, defining constraints – Primary key, foreign key, unique, not null, check, IN operator, Functions - aggregate functions, Built-in functions –numeric, date, string functions, set operations, sub-queries, correlated sub-queries, use of group by, having, order by, join and its types, Exist, Any, All, view and its types. transaction control commands – Commit, Rollback, Save point CHAPTER 2.2 Cursors, Stored Procedures, Stored Function, Database Triggers Unit-3 Views , Packages and procedures , triggers, Transection management and concurrency control. Contact Hours:4 CHAPTER 3.1 Package, Procedures and Triggers: Parts of procedures, Parameter modes, Advantages of procedures, Syntax for creating triggers, Types of triggers, package specification and package body, developing a package, Bodiless package, Advantages of packages.
  • 4. Contents of the Syllabus CHAPTER 3.2 Transaction Management and Concurrency Control: Introduction to Transaction Processing, Properties of Transactions, Serializability and Recoverability, Need for Concurrency Control, Locking Techniques, Time Stamping Methods, Optimistic Techniques, Granularity of Data items, Database Recovery of database: Introduction, Need for Recovery, Types of errors, Recovery Techniques.
  • 5. Department of Computer Science and Engineering (CSE) University Institute of Engineering (UIE) OBJECTIVES At the completion of this Chapter , students should be able to do the following: • Understand the role of a database management system in an organization. • Understand basic database concepts, including the structure and operation of the relational data model.
  • 6. Department of Computer Science and Engineering (CSE) University Institute of Engineering File system vs. Database system File System- • Data storage traditionally used individual, unrelated files, sometimes called flat files. • In the past, each application program in an organization used its own file. • In a university, for example, each department might have its own set of files: the record office kept a file about the student information and their grades, the scheduling office kept the name of the professors and the courses they were teaching, the payroll department kept its own file about the whole staff and so on. • Today, however, all of these flat files can be combined in a single entity; the database for the whole university
  • 7. Department of Computer Science and Engineering (CSE) University Institute of Engineering Data vs. Informtion
  • 8. Department of Computer Science and Engineering (CSE) University Institute of Engineering Database Management System (DBMS) • The related information when placed is an organized form makes a database. • The organization of data/information is necessary because unorganized information has no meaning. • Collection of interrelated data • Set of programs to access the data • DBMS contains information about a particular enterprise • DBMS provides an environment that is both convenient and efficient to use. • Database Applications: – Banking: all transactions – Airlines: reservations, schedules – Universities: registration, grades – Sales: customers, products, purchases – Manufacturing: production, inventory, orders, supply chain – Human resources: employee records, salaries, tax deductions • Databases touch all aspects of our lives
  • 9. Department of Computer Science and Engineering (CSE) University Institute of Engineering Purpose of Database System • In the early days, database applications were built 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 provide a way of ensuring that changes made to the database by authorized users do not result in a loss of data consistency. • Hard to add new constraints or change existing ones
  • 10. Department of Computer Science and Engineering (CSE) University Institute of Engineering Purpose of Database System • Drawbacks of using file systems (cont.) – Atomicity of updates • Failures may leave database in an inconsistent state with partial updates carried out • E.g. transfer of funds from one account to another should either complete or not happen at all – Concurrent access by multiple users • Concurrent accessed needed for performance • Uncontrolled concurrent accesses can lead to inconsistencies – E.g. two people reading a balance and updating it at the same time – Security problems • Database systems offer solutions to all the above problems
  • 11. Department of Computer Science and Engineering (CSE) University Institute of Engineering Disadvantages of Traditional File system • Data Redundancy Since each application has its own data file, the same data may have to be recorded and stored in many files For example- Personal file and payroll file, both contain data on employee name, designation etc. The result is unnecessary duplicate or redundant data items. This redundancy requires additional or higher storage space, costs extra time and money, and requires additional efforts to keep all files upto-date.
  • 12. Department of Computer Science and Engineering (CSE) University Institute of Engineering • Data Inconsistency Data redundancy leads to data inconsistency especially when data is to be updated. Data inconsistency occurs due to the same data items that appear in more than one file do not get updated simultaneously in each and every file. • Lack of Data Integration • Data Dependence • Limited Data Sharing • Poor Data Control • Problem of Security • Data Manipulation Capability is Inadequate Disadvantages of Traditional File system
  • 13. Department of Computer Science and Engineering (CSE) Operations on Databases University Institute of Engineering
  • 14. Department of Computer Science and Engineering (CSE) University Institute of Engineering Advantages of Databases • Less redundancy – In a flat-file system there is a lot of redundancy. For example, in the flat file system for a university, the names of professors and students are stored in more than one file. • Inconsistency avoidance When the same data is duplicated and changes are made at one site, which is not propagated to the other site, it gives rise to inconsistency and the two entries regarding the same data will not agree. – If the same piece of information is stored in more than one place, then any changes in the data need to occur in all places that data is stored.
  • 15. Department of Computer Science and Engineering (CSE) University Institute of Engineering • Efficiency – A database is usually more efficient that a flat file system, because a piece of information is stored in fewer locations. • Data integrity • Integrity of data means that data in database is always accurate, such that incorrect information cannot be stored in database. – In a database system it is easier to maintain data integrity, because a piece of data is stored in fewer locations. • Confidentiality – It is easier to maintain the confidentiality of the information if the storage of data is centralized in one location. Advantages of Databases
  • 16. Department of Computer Science and Engineering (CSE) University Institute of Engineering • Data can be shared • Providing Backup and Recovery • Standards can be enforced • Restricting unauthorized access • Solving enterprise requirement than individual requirement Advantages of Databases
  • 17. Department of Computer Science and Engineering (CSE) University Institute of Engineering Disadvantages of DBMS • Complexity • Size • Performance • Higher impact of a failure • Cost of DBMS • Additional Hardware costs • Cost of Conversion
  • 18. Department of Computer Science and Engineering (CSE) University Institute of Engineering Use a DBMS when this is important • persistent storage of data • centralized control of data • control of redundancy • control of consistency and integrity • multiple user support • sharing of data • data documentation • data independence • control of access and security • backup and recovery Do not use a DBMS when • the initial investment in hardware, software, and training is too high • the generality a DBMS provides is not needed • the overhead for security, concurrency control, and recovery is too high • data and applications are simple and stable • real-time requirements cannot be met by it • multiple user access is not needed
  • 19. Department of Computer Science and Engineering (CSE) University Institute of Engineering File Management e.g. COBOL or C++ Program • Small systems • Relatively Cheap • Few Files • Files are Files • Simple Structure • Redundant Data • Chances of Inconsistency • Isolated Data • Little Preliminary Design • Integrity Left to application Programmer • NO Security • Simple, Primitive backup/Recovery • Often Single User • Large systems • Relatively Expensive • Many Files • Files are Tables • Complex Structure • Reduced Redundancy • Consistent • Data can be Shared • Vast Preliminary Design • Rigorous inbuilt Integrity checking • Rigorous Security • Complex & Sophisticated backup/Recovery • Multiple Users Database Management e.g. Oracle
  • 20. BASIC DEFINITIONS ⮚Database: A collection of related data. ⮚Data: Known facts that can be recorded and have an implicit meaning. ⮚Database Management System (DBMS): A software package/ system to facilitate the creation and maintenance of a computerized database. ⮚Database System: The DBMS software together with the data itself. Sometimes, the applications are also included. Department of Computer Science and Engineering (CSE)
  • 21. Department of Computer Science and Engineering (CSE) University Institute of Engineering Outcomes • Differentiate database systems from file systems by enumerating the features provided by database systems and describe each in both function and benefit. • Define the terminology, features, classifications, and characteristics embodied in database systems. • Master the basic concepts and appreciate the applications of database systems.
  • 22. Department of Computer Science and Engineering (CSE) University Institute of Engineering References • Database System Concepts by Abraham Silberschatz • Database System Concepts by Sudarshan, Korth Education) (McGraw-Hill • Fundamentals of Database System By Elmasari &Navathe- Pearson Education • http://ecomputernotes.com/database-system/rdbms • https://www.tutorialspoint.com/sql/sql-rdbms-concepts.htm • https://www.studytonight.com/dbms/rdbms-concept
  • 23. Department of Computer Science and Engineering (CSE) University Institute of Engineering (UIE)
  • 24. Department of Computer Science and Engineering (CSE) University Institute of Engineering (UIE) OBJECTIVES At the completion of this Chapter , students should be able to do the following: • Understand DBMS Architecture • Appreciate the evolution of ANSI SPARC (3 level architecture)
  • 25. Department of Computer Science and Engineering (CSE) University Institute of Engineering (UIE) Introduction ANSI American National Standards Institute SPARC Standards Planning And Requirements Committee • It is an abstract design standard for a Database Management System (DBMS), first proposed in 1975.
  • 26. Department of Computer Science and Engineering (CSE) University Institute of Engineering (UIE)
  • 27. Department of Computer Science and Engineering (CSE) University Institute of Engineering (UIE) Three-level architecture • External level • Conceptual level • Internal level • The Three Level Architecture has the aim of enabling users to access the same data but with a personalized view of it. The distancing of the internal level from the external level means that users do not need to know how the data is physically stored in the database. This level separation also allows the Database Administrator (DBA) to change the database storage structures without affecting the users' views.
  • 28. Department of Computer Science and Engineering (CSE) University Institute of Engineering (UIE) Three-level architecture • External Level (User Views): A user's view of the database describes a part of the database that is relevant to a particular user. It excludes irrelevant data as well as data which the user is not authorized to access. • Conceptual Level: The conceptual level is a way of describing what data is stored within the whole database and how the data is inter-related. The conceptual level does not specify how the data is physically stored. • Internal Level: The internal level involves how the database is physically represented on the computer system. It describes how the data is actually stored in the database and on the computer hardware.
  • 29. Department of Computer Science and Engineering (CSE) University Institute of Engineering (UIE) Objective of the three-level architecture • It allows independent customized user views: Each user should be able to access the same data, but have a different customized view of the data. These should be independent: changes to one view should not affect others. • It hides the physical storage details from users: Users should not have to deal with physical database storage details. • The database administrator should be able to change the database storage structures without affecting the users’ views. • The internal structure of the database should be unaffected by changes to the physical aspects of the storage: For example, a changeover to a new disk.
  • 30. Department of Computer Science and Engineering (CSE) University Institute of Engineering (UIE) Database schemas There are three different types of schema corresponding to the three levels in the ANSI-SPARC architecture. Schema is the structure of the database that defines the objects in the database • The external schemas describe the different external views of the data and there may be many external schemas for a given database. • The conceptual schema describes all the data items and relationships between them, together with integrity constraints (later). There is only one conceptual schema per database. • The internal schema at the lowest level contains definitions of the stored records, the methods of representation, the data fields, and indexes. There is only one internal schema per database.
  • 31. Department of Computer Science and Engineering (CSE) The way users perceiv e the data. University Institute of Engineering (UIE) The way the DBMS and OS perceive the data.
  • 32. Department of Computer Science and Engineering (CSE) University Institute of Engineering (UIE) Mapping between views • Three view-levels are described by means of three schemas. • These schemas are stored in the data dictionary. • In DBMS, each user refers only to its own external schema. • Hence, the DBMS must transform a request on. a specified external schema into a request against conceptual schema, and then into a request against internal schema to store and retrieve data to and from the database. • The process to convert a request (from external level) and the result between view levels is called mapping. • The mapping defines the correspondence between three view levels. • The mapping description is also stored in data dictionary. • The DBMS is responsible for mapping between these three types of schemas.
  • 33. Department of Computer Science and Engineering (CSE) University Institute of Engineering (UIE) Mapping between views There are two types of mapping. (i) External-Conceptual mapping • An external-conceptual mapping defines the correspondence between a particular external view and the conceptual view. • The external-conceptual mapping tells the DBMS which objects on the conceptual level correspond to the objects requested on a particular user's external view. • If changes are made to either an external view or conceptual view, then mapping must be changed accordingly. (ii) Conceptual-Internal mapping • The conceptual-internal mapping defines the correspondence between the conceptual view and the internal view, i.e. database stored on the physical storage device. • It describes how conceptual records are stored and retrieved to and from the storage device.
  • 34. Department of Computer Science and Engineering (CSE) University Institute of Engineering (UIE) Example
  • 35. Department of Computer Science and Engineering (CSE) University Institute of Engineering (UIE) Data Independence • The ability to modify a scheme definition in one level without affecting a scheme definition in a higher level is called data independence. There are two kinds: • Logical data independence • Physical data independence
  • 36. Department of Computer Science and Engineering (CSE) University Institute of Engineering (UIE) Data Independence Logical data independence • The ability to modify the conceptual scheme without causing application programs to be rewritten. • Immunity of external schemas to changes in the conceptual schema. • The change would be absorbed by mapping between external and conceptual levels. Physical data independence • The ability to modify the internal scheme or physical storage structures and devices without affecting conceptual or external schemas . • Modifications at this level are usually to improve performance. Logical data independence is difficult to achieve than physical data independence.
  • 37. Department of Computer Science and Engineering (CSE) University Institute of Engineering (UIE) Database Administrator (DBA) • A database administrator (DBA) is an IT professional responsible for the installation, configuration, upgrading, administration, monitoring, maintenance, and security of databases in an organization.
  • 38. Department of Computer Science and Engineering (CSE) University Institute of Engineering (UIE) Responsibilities of DBA Makes decisions concerning the content of the database. ✔ Identify the entities of interest to the enterpriseand to identify information to be recorded about those entities Plans storage structures and access strategies. ✔ How the data is to be represented in the database. ✔ Specify the representation by writing the storage structure definition (using the internal data definition language). ✔ The associated mapping between the storage structure definition and the conceptual schema must also be specified. Provides support to users. ✔ Ensure that the data users require is available,and to write the necessary external schemas. ✔ The mapping between any given eA1ernal schema and the conceptual' schema must also be specified.
  • 39. Department of Computer Science and Engineering (CSE) University Institute of Engineering (UIE) Responsibilities of DBA Defines security and integrity checks. ✔ Providing the authorization and authentication checks such that no malicious users can access database and it must remain protected. ✔ DBA must also ensure the integrity of the database. Interprets backup and recovery strategies. ✔ Define and implement an appropriate recovery strategy to recover he database from all types of failures. Monitoring performance and responding to changes in requirements. ✔ DBA is responsible for so organizing the system as to get the performance that is "best for the enterprise," and for making the appropriate adjustments as requirements change.
  • 40. Department of Computer Science and Engineering (CSE) University Institute of Engineering (UIE) Outcomes • Analyze an information storage problem and derive an information model expressed in the form of an entity relation diagram and other optional analysis forms, such as a data dictionary. • Demonstrate an understanding of the relational data model. • Appreciate the roles & responsibilities of DBA.
  • 41. Department of Computer Science and Engineering (CSE) University Institute of Engineering (UIE) References • Database System Concepts by Abraham Silberschatz • Database System Concepts by Sudarshan, Korth Education) (McGraw- Hill • Fundamentals of Database SystemBy Elmasari &Navathe- Pearson Education • http://ecomputernotes.com/database-system/rdbms • https://www.tutorialspoint.com/sql/sql-rdbms-concepts.htm • https://www.studytonight.com/dbms/rdbms-concept
  • 42. Department of Computer Science and Engineering (CSE) University Institute of Engineering (UIE)
  • 43. University Institute of Engineering (UIE) 46 Database Management System CO Number Title Level CO1 To perceive the significance and implementation of a commercial relational database system (Oracle) by writing SQL using the system. Remember CO2 To understand the relational database theory, and be able to write relational algebra expressions for queries Understand CO3 To identify the basic issues of transaction processing and concurrency control and find out its solutions. Analysis and application Course Outcome Will be covered in this lecture Department of Computer Science and Engineering (CSE)
  • 44. University Institute of Engineering (UIE) Department of Computer Science and Engineering (CSE) Contents of the Syllabus 47 UNIT-I [10h] Overview of Databases: Database concepts, DBMS, Data Base System Architecture (Three Level ANSI-SPARC Architecture), Advantages and Disadvantages of DBMS, Data Independence, DBA and Responsibilities of DBA, Relational Data Structure, Keys, Relations, Attributes, Schema and Instances, Referential integrity, Entity integrity. Data Models: Relational Model, Network Model, Hierarchical Model, ER Model: Design, issues, Mapping constraints, ER diagram, Comparison of Models. Relational Algebra & Relational Calculus: Introduction, Syntax, Semantics, Additional operators, Grouping and Ungrouping, Relational comparisons, Tuple Calculus, Domain Calculus, Calculus Vs Algebra, Computational capabilities. UNIT-II [10h] Functional dependencies and Normalization: Functional dependencies, Decomposition, Full Functional Dependency (FFD), Transitive Dependency (TD), Join Dependency (JD), Multi-valued Dependency (MVD), Normal Forms (1NF, 2NF, 3NF, BCNF), De-normalization. Database Security: Introduction, Threats, Counter Measures. Control Structures: Introduction to conditional control, Iterative control and sequential control statements, Cursors, Views.
  • 45. University Institute of Engineering (UIE) Department of Computer Science and Engineering (CSE) Contents of the Syllabus 48 UNIT-III [10h] Package, Procedures and Triggers: Parts of procedures, Parameter modes, Advantages of procedures, Syntax for creating triggers, Types of triggers, package specification and package body, developing a package, Bodiless package, Advantages of packages. Transaction Management and Concurrency Control: Introduction to Transaction Processing, Properties of Transactions, Serializability and Recoverability, Need for Concurrency Control, Locking Techniques, Time Stamping Methods, Optimistic Techniques and Granularity of Data items. Database Recovery of database: Introduction, Need for Recovery, Types of errors, Recovery Techniques.
  • 46. University Institute of Engineering (UIE) Department of Computer Science and Engineering (CSE) 49 Chapter 1.2 (Data Models) Data Models: Relational Model, Network Model, Hierarchical Model, ER Model: Design, issues, Mapping constraints, ER diagram, Comparison of Models.
  • 47. University Institute of Engineering (UIE) Department of Computer Science and Engineering (CSE) Learning Objective • Method to organize data required in an application as relations. • Importance for an integrated database in organizations. • Goals of Data Base Management systems (DBMS). • Entity-Relationship(ER) modeling to develop a conceptual model of data. • Structure and organization of DBMS
  • 48. University Institute of Engineering (UIE) Department of Computer Science and Engineering (CSE) Learning Outcome • Define program-data independence, data models for database systems, database schema and database instances. • Identify the methodology of conceptual modeling through Entity Relationship model. • Identify the methodology of logical model. • Identify the methodology of physical model.
  • 49. University Institute of Engineering (UIE) Department of Computer Science and Engineering (CSE) Entity-Relationship Model..contd Relationships: Link between different entities of the database is called relationship. Mapping Cardinalities Cardinality defines the number of entities in one entity set, which can be associated with the number of entities of other set via relationship set. •Express the number of entities to which another entity can be associated via a relationship set. •Most useful in describing binary relationship sets.
  • 50. University Institute of Engineering (UIE) Department of Computer Science and Engineering (CSE) Types of Relationships One - One Relationship:- (1 – 1) Each value in the first table could relate with only one record in the second table. One – Many Relationship:- (1 - ∞) Each value in the first table could relate with many records in the second table. Many – Many Relationship (∞ - ∞) Each value in the first table could relate with many records in the second table and each value of the second table could relate with many records in the first table. Many – One Relationship(∞-1) •More than one entities from entity set A can be associated with at most one entity of entity set B, however an entity from entity set B can be associated with more than one entity from entity set A.
  • 51. University Institute of Engineering (UIE) Department of Computer Science and Engineering (CSE) Relationships….contd One - One Relationship:- (1 – 1) Each value in the first table could relate with only one record in the second table.
  • 52. University Institute of Engineering (UIE) Department of Computer Science and Engineering (CSE) Relationships….contd One – Many Relationship:- (1 - ∞) Each value in the first table could relate with many records in the second table.
  • 53. University Institute of Engineering (UIE) Department of Computer Science and Engineering (CSE) Relationships….contd • Many-to-many − One entity from A can be associated with more than one entity from B and vice versa
  • 54. University Institute of Engineering (UIE) Department of Computer Science and Engineering (CSE) Relationships….contd • Many-to-one − More than one entities from entity set A can be associated with at most one entity of entity set B, however an entity from entity set B can be associated with more than one entity from entity set A.
  • 55. University Institute of Engineering (UIE) Department of Computer Science and Engineering (CSE) E-R Diagrams • ER Diagram stands for Entity Relationship Diagram, also known as ERD is a diagram that displays the relationship of entity sets stored in a database. In other words, ER diagrams help to explain the logical structure of databases. ER diagrams are created based on three basic concepts: entities, attributes and relationships. • ER Diagrams contain different symbols that use rectangles to represent entities, ovals to define attributes and diamond shapes to represent relationships. • At first look, an ER diagram looks very similar to the flowchart. However, ER Diagram includes many specialized symbols, and its meanings make this model unique. The purpose of ER Diagram is to represent the entity framework infrastructure.
  • 56. University Institute of Engineering (UIE) Department of Computer Science and Engineering (CSE) E-R Diagrams Symbols • Entity Relationship Diagram Symbols & Notations mainly contains three basic symbols which are rectangle, oval and diamond to represent relationships between elements, entities and attributes. There are some sub-elements which are based on main elements in ERD Diagram. ER Diagram is a visual representation of data that describes how data is related to each other using different ERD Symbols and Notations. • Following are the main components and its symbols in ER Diagrams: • Rectangles: This Entity Relationship Diagram symbol represents entity types • Ellipses : Symbol represent attributes • Diamonds: This symbol represents relationship types • Lines: It links attributes to entity types and entity types with other relationship types • Primary key: attributes are underlined • Double Ellipses: Represent multi-valued attributes
  • 57. University Institute of Engineering (UIE) Department of Computer Science and Engineering (CSE) E-R Diagrams Symbols
  • 58. University Institute of Engineering (UIE) Department of Computer Science and Engineering (CSE) E-R Diagrams ● Rectangles represent entity sets. ● Diamonds represent relationship sets. ● Lines link attributes to entity sets and entity sets to relationship sets. ● Ellipses represent attributes ● Double ellipses represent multivalued attributes. ● Dashed ellipses denote derived attributes. ● Underline indicates primary key attributes (will study later)
  • 59. University Institute of Engineering (UIE) Department of Computer Science and Engineering (CSE) E-R Diagram With Composite, Multivalued, and Derived Attributes
  • 60. University Institute of Engineering (UIE) Department of Computer Science and Engineering (CSE) Usage of E-R Diagrams • Helps you to define terms related to entity relationship modeling • Provide a preview of how all your tables should connect, what fields are going to be on each table • Helps to describe entities, attributes, relationships • ER diagrams are translatable into relational tables which allows you to build databases quickly • ER diagrams can be used by database designers as a blueprint for implementing data in specific software applications • The database designer gains a better understanding of the information to be contained in the database with the help of ERP diagram • ERD Diagram allows you to communicate with the logical structure of the database to users
  • 61. University Institute of Engineering (UIE) Department of Computer Science and Engineering (CSE) Design Issues • Use of entity sets vs. attributes Choice mainly depends on the structure of the enterprise being modeled, and on the semantics associated with the attribute in question. • Use of entity sets vs. relationship sets Possible guideline is to designate a relationship set to describe an action that occurs between entities • Binary versus n-ary relationship sets Although it is possible to replace any nonbinary (n-ary, for n > 2) relationship set by a number of distinct binary relationship sets, a n-ary relationship set shows more clearly that several entities participate in a single relationship. • Placement of relationship attributes
  • 62. University Institute of Engineering (UIE) Department of Computer Science and Engineering (CSE) 65 Data Models: A Summary • Each new data model capitalized on the shortcomings of previous models • Common characteristics: – Conceptual simplicity without compromising the semantic completeness of the database – Represent the real world as closely as possible – Representation of real-world transformations (behavior) must comply with consistency and integrity characteristics of any data model
  • 63. University Institute of Engineering (UIE) Department of Computer Science and Engineering (CSE) Data Models: A Summary
  • 64. University Institute of Engineering (UIE) Department of Computer Science and Engineering (CSE) Data Dictionary It contains information about the data attributes, elements relationship, user details, security restrictions and integrity constraints.
  • 65. University Institute of Engineering (UIE) Department of Computer Science and Engineering (CSE) Data Definition Language (DDL) • ■ Specification notation for defining the database schema – ★ E.g. create table account ( account-number char(10), balance integer) • ■ DDL compiler generates a set of tables stored in a data dictionary • ■ Data dictionary contains metadata (i.e., data about data) – ★ database schema – ★ Data storage and definition language • ✔ language in which the storage structure and access methods used by the database system are specified • ✔ Usually an extension of the data definition language
  • 66. University Institute of Engineering (UIE) Department of Computer Science and Engineering (CSE) Data Manipulation Language (DML) • ■ Language for accessing and manipulating the data organized by the appropriate data model – ★ DML also known as query language • ■ Two classes of languages – ★ Procedural – user specifies what data is required and how to get those data – ★ Nonprocedural – user specifies what data is required without specifying how to get those data • ■ SQL is the most widely used query language
  • 67. University Institute of Engineering (UIE) Department of Computer Science and Engineering (CSE) FAQ 1.Define DBMS? List Database system Applications. 2. Discuss Database Administrator’s responsibilities. 3. What do you understand by dimension and attribute? 4. What is a fact & a fact table? 5. List out few common mistakes encountered during Data Modelling? 6. What do you understand by Data Modelling? 7. Explain your understanding of different data models?
  • 68. University Institute of Engineering (UIE) Department of Computer Science and Engineering (CSE) References OTHER REFRENCES • ER Diagram: Entity Relationship Diagram Model | DBMS Example (guru99.com) • ER Diagram Representation - Tutorialspoint • Entity Relationship Diagram - ER Diagram in DBMS (beginnersbook.com) • SUGGESTED BOOK REFERENCES • Ramez Elmasri and Shamkant B. Navathe,“Fundamentals of Database System”, The Benjamin / Cummings Publishing Co. • Korth and Silberschatz Abraham, “Database SystemConcepts”, McGraw Hall. • Pratt,”DBMS”, Cengage Learning.
  • 69. University Institute of Engineering (UIE) 73 Database Management System CO Number Title Level CO1 To perceive the significance and implementation of a commercial relational database system (Oracle) by writing SQL using the system. Remember CO2 To understand the relational database theory, and be able to write relational algebra expressions for queries Understand CO3 To identify the basic issues of transaction processing and concurrency control and find out its solutions. Analysis and application Course Outcome Will be covered in this lecture Department of Computer Scienceand Engineering (CSE)
  • 70. University Institute of Engineering (UIE) Department of Computer Science and Engineering (CSE) Contents of the Syllabus 74 UNIT-I [10h] Overview of Databases: Database concepts, DBMS, Data Base System Architecture (Three Level ANSI-SPARC Architecture), Advantages and Disadvantages of DBMS, Data Independence, DBA and Responsibilities of DBA, Relational Data Structure, Keys, Relations, Attributes, Schema and Instances, Referential integrity, Entity integrity. Data Models: Relational Model, Network Model, Hierarchical Model, ER Model: Design, issues, Mapping constraints, ER diagram, Comparison of Models. Relational Algebra & Relational Calculus: Introduction, Syntax, Semantics, Additional operators, Grouping and Ungrouping, Relational comparisons, Tuple Calculus, Domain Calculus, Calculus Vs Algebra, Computational capabilities. UNIT-II [10h] Functional dependencies and Normalization: Functional dependencies, Decomposition, Full Functional Dependency (FFD), Transitive Dependency (TD), Join Dependency (JD), Multi-valued Dependency (MVD), Normal Forms (1NF, 2NF, 3NF, BCNF), De-normalization. Database Security: Introduction, Threats, Counter Measures. Control Structures: Introduction to conditional control, Iterative control and sequential control statements, Cursors, Views.
  • 71. University Institute of Engineering (UIE) Department of Computer Science and Engineering (CSE) Contents of the Syllabus 75 UNIT-III [10h] Package, Procedures and Triggers: Parts of procedures, Parameter modes, Advantages of procedures, Syntax for creating triggers, Types of triggers, package specification and package body, developing a package, Bodiless package, Advantages of packages. Transaction Management and Concurrency Control: Introduction to Transaction Processing, Properties of Transactions, Serializability and Recoverability, Need for Concurrency Control, Locking Techniques, Time Stamping Methods, Optimistic Techniques and Granularity of Data items. Database Recovery of database: Introduction, Need for Recovery, Types of errors, Recovery Techniques.
  • 72. University Institute of Engineering (UIE) Department of Computer Science and Engineering (CSE) 76 Chapter 1.2 (Data Models) Data Models: Relational Model, Network Model, Hierarchical Model, ER Model: Design, issues, Mapping constraints, ER diagram, Comparison of Models.
  • 73. University Institute of Engineering (UIE) Department of Computer Science and Engineering (CSE) Learning Objective • Method to organize data required in an application as relations. • Importance for an integrated database in organizations. • Goals of Data Base Management systems (DBMS). • Entity-Relationship(ER) modeling to develop a conceptual model of data. • Structure and organization of DBMS
  • 74. University Institute of Engineering (UIE) Department of Computer Science and Engineering (CSE) Learning Outcome • Define program-data independence, data models for database systems, database schema and database instances. • Identify the methodology of conceptual modeling through Entity Relationship model. • Identify the methodology of logical model. • Identify the methodology of physical model.
  • 75. University Institute of Engineering (UIE) Department of Computer Science and Engineering (CSE) Relationship Types • Specialization • Generalization • Aggregation
  • 76. University Institute of Engineering (UIE) Department of Computer Science and Engineering (CSE) 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).
  • 77. University Institute of Engineering (UIE) Department of Computer Science and Engineering (CSE) 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. 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.
  • 78. University Institute of Engineering (UIE) Department of Computer Science and Engineering (CSE) 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).
  • 79. University Institute of Engineering (UIE) Comparison of Record based model Hierarchical Network Relational Relationship between records is of parent child type. Relationship between records is expressed in the form of pointers or links Relationship between records is represented by a relation that contains a key for each record involved in the relatonship. Many to Many relationship cannot be expressed in this model Many to Many relationship can be easily implemented. Many to Many relationship can also be implemented. It is simple, straightforward and natural method of implementing record relationships Record relationship implementation is very complex due to the use of pointers Relationship implementation is very easy through the use of a key or composite key field
  • 80. University Institute of Engineering (UIE) Comparison of Record based model Hierarchical Network Relational This type of model is useful only when there is some hierarchical character in the database Network model is useful for representing such records which have many to many relationships Relational model is useful for representing most of the real world objects and relationships among them In order to represent links among records, pointers are used. Thus relations among records are physical In network model also the record relations are physical Relational model does not maintain physical connection among record. Data is organized logically in the form of rows and columns, and stored in table. Searching for record is very difficult since one can retrieve a child only after going through its parent record Searching a record is easy since there are multiple access paths to a data elements. A unique indexed key field Is used to search for a data element.
  • 81. University Institute of Engineering (UIE) Department of Computer Science and Engineering (CSE) 85 Data Models: A Summary • Each new data model capitalized on the shortcomings of previous models • Common characteristics: – Conceptual simplicity without compromising the semantic completeness of the database – Represent the real world as closely as possible – Representation of real-world transformations (behavior) must comply with consistency and integrity characteristics of any data model
  • 82. University Institute of Engineering (UIE) Department of Computer Science and Engineering (CSE) Data Models: A Summary
  • 83. University Institute of Engineering (UIE) Department of Computer Science and Engineering (CSE) Data Dictionary It contains information about the data attributes, elements relationship, user details, security restrictions and integrity constraints.
  • 84. University Institute of Engineering (UIE) Department of Computer Science and Engineering (CSE) Data Definition Language (DDL) • ■ Specification notation for defining the database schema – ★ E.g. create table account ( account-number char(10), balance integer) • ■ DDL compiler generates a set of tables stored in a data dictionary • ■ Data dictionary contains metadata (i.e., data about data) – ★ database schema – ★ Data storage and definition language • ✔ language in which the storage structure and access methods used by the database system are specified • ✔ Usually an extension of the data definition language
  • 85. University Institute of Engineering (UIE) Department of Computer Science and Engineering (CSE) Data Manipulation Language (DML) • ■ Language for accessing and manipulating the data organized by the appropriate data model – ★ DML also known as query language • ■ Two classes of languages – ★ Procedural – user specifies what data is required and how to get those data – ★ Nonprocedural – user specifies what data is required without specifying how to get those data • ■ SQL is the most widely used query language
  • 86. University Institute of Engineering (UIE) Department of Computer Science and Engineering (CSE) SQL COMPONENTS SQL consists of three components: 1. Data Definition Language (DDL) 2. Data Manipulation Language (DML) 3. Data Control Language (DCL)
  • 87. University Institute of Engineering (UIE) Department of Computer Science and Engineering (CSE) DATA DEFINITION LANGUAGE (DDL) This component of the SQL language is used to create and modify tables and other objects in the database. For tables there are three main commands: CREATE TABLE tablename  to create a table in the database DROP TABLE tablename  to remove a table from the database ALTER TABLE tablename  to add or remove columns from a table in the database RENAME <new table name> to <old table name>;  To change the name of a table as per the user’s wish or requirement. TRUNCATE TABLE<table name>;  Truncate Tables empties the table completely. Once the data deleted cannot be retrieved. DESC tablename  To view just the blank table
  • 88. University Institute of Engineering (UIE) Department of Computer Science and Engineering (CSE) CREATE TABLE COMMAND Purpose:- Tables are the basic unit of data storage in an Oracle Database. Data is stored in rows and columns. Syntax:- Create table <TableName> (<ColumnName1> <Data Type>(<Size>), <ColumnName2> <Data Type>(<Size>), ………..<ColumnName n> <Data Type>(<Size>)); Example:- Create table STUDENT (Roll_no number(5), Name varchar2(20), Branch varchar2(10));
  • 89. University Institute of Engineering (UIE) Department of Computer Science and Engineering (CSE) ALTER TABLE COMMAND Purpose:- The structure of a table can be modified by using a alter table command. Alter Table allows changing the structure of an existing table. With Alter Table it is possible to add or delete columns, create or destroy indexes, change the data type of existing columns, or rename columns or the table itself Syntax:- Adding New Columns Alter table <table name> add(<new col name> <data type> (<Size>), <new col name> <data type> (<Size>),…..); Modifying Existing Column Alter table <table name> modify(<col name> <new data type> (< new Size>), <col name> <new data type> (<new Size>),…..); Dropping A Column Alter table <table name> drop column <col name>;
  • 90. University Institute of Engineering (UIE) Department of Computer Science and Engineering (CSE) Example:- Alter table STUDENT add( Telephone number(10)); Alter table STUDENT modify( Telephone number(20)); Alter table STUDENT drop column Telephone;
  • 91. University Institute of Engineering (UIE) Department of Computer Science and Engineering (CSE) RENAME TABLE COMMAND Purpose:- To change the name of a table as per the user’s wish or requirement. Syntax:- Rename <new table name> to <old table name>; Example:- Rename STUDENT to group_a101;
  • 92. University Institute of Engineering (UIE) Department of Computer Science and Engineering (CSE) DROP TABLE COMMAND Purpose:- Sometimes table in the database becomes obsolete and need to be discarded, so we use drop table command. Syntax:- Drop table <table name>; Example:- Drop table CSEA_Data101;
  • 93. University Institute of Engineering (UIE) Department of Computer Science and Engineering (CSE) DATA MANIPULATION LANGUAGE (DML) DML component of the SQL language is used to manipulate data within a table. There are four main commands: SELECT  to select rows of data from a table INSERT  to insert rows of data into a table UPDATE  to change rows of data in a table DELETE  to remove rows of data from a table
  • 94. University Institute of Engineering (UIE) Department of Computer Science and Engineering (CSE) INSERT COMMAND Command:- Insert data into a table Purpose:- The Insert Into Table command is used to load the created table with data to be manipulated later. Syntax:- Insert into <table name>(<col1>,<col2>,……..,<col n>) values (<expression1>, <expression2> ,……,<expression3>); Example:- Insert into STUDENT values(101, ‘Aanchal’, ’CSE’); Insert into STUDENT values(126, ‘Jotnain’, ’CSE’); Insert into STUDENT values(149, ‘Sapanpreet’, ’ECE’); Insert into STUDENT values(151, ‘Savita’, ’CSE’);
  • 95. University Institute of Engineering (UIE) Department of Computer Science and Engineering (CSE) INSERT DATA INTO A TABLE FROM A TABLE (Copying contents of a table to another table) Command:- Insert into….Select Purpose:- To filter the data that is not required Syntax:- Insert into <table name>Select <col name1>, <col name2>…. from <table name>; Example:- Insert into CSEA_Data101 Select roll_no,name from STUDENT where roll_no=149;
  • 96. University Institute of Engineering (UIE) Department of Computer Science and Engineering (CSE) SELECT COMMAND Command:- (a) Selecting all rows and all columns Purpose:- This command is used to view all the rows and columns of the table created in the database. Syntax:- Select * from <table name>; Example:- Select * from STUDENT;
  • 97. University Institute of Engineering (UIE) Department of Computer Science and Engineering (CSE) SELECT COMMAND (b) Selected rows and all columns using where clause Purpose:- If the information of a particular student is to be retrieved from a table, its retrieval must be based on a specific condition Syntax:- Select * from <table name> where <condition>; Example:- Select * from STUDENT where roll_no=151;
  • 98. University Institute of Engineering (UIE) Department of Computer Science and Engineering (CSE) ALIAS Purpose:- SQL aliases are used to give a table, or a column in a table, a temporary name. ALIAS COLUMN SYNTAX Syntax:- SELECT column_name AS alias_name FROM table_name; Example:- SELECT CustomerID AS ID, CustomerName AS Customer FROM Customers;
  • 99. University Institute of Engineering (UIE) Department of Computer Science and Engineering (CSE) ALIAS TABLE SYNTAX Syntax:- SELECT column_name(s) FROM table_name AS alias_name; Example:- SELECT o.OrderID, o.OrderDate, c.CustomerName FROM Customers AS c, Orders AS o WHERE c.CustomerName='Around the Horn' AND c.CustomerID=o.CustomerID;
  • 100. University Institute of Engineering (UIE) Department of Computer Science and Engineering (CSE) DELETE COMMAND Purpose:- To delete the rows from the table that satisfies the condition provided by its where clause and returns the number of records deleted. Syntax:- Removal of all rows Delete from <table name>; Removal of Specific Row(s) Delete from <table name> where <condition>; Example:- Delete from CSEA_Data101 where rollno=149; Delete from CSEA_Data101;
  • 101. University Institute of Engineering (UIE) Department of Computer Science and Engineering (CSE) DELETE & TRUNCATE TRUNCATE  TRUNCATE is a DDL command  TRUNCATE is executed using a table lock and the whole table is locked to remove all records.  We cannot use the WHERE clause with TRUNCATE.  TRUNCATE removes all rows from a table.  Minimal logging in the transaction log, so it is faster performance-wise. DELETE  DELETE is a DML command.  DELETE is executed using a row lock, each row in the table is locked for deletion.  We can use where clause with DELETE to filter & delete specific records.  The DELETE command is used to remove rows from a table based on WHERE condition.  It maintains the log, so it slower than TRUNCATE.
  • 102. University Institute of Engineering (UIE) Department of Computer Science and Engineering (CSE) DROP COMMAND 1. The DROP command removes a table from the database. 2. All the tables' rows, indexes, and privileges will also be removed. 3. No DML triggers will be fired. 4. The operation cannot be rolled back. 5. DROP and TRUNCATE are DDL commands, whereas DELETE is a DML command. 6. DELETE operations can be rolled back (undone), while DROP and TRUNCATE operations cannot be rolled back
  • 103. University Institute of Engineering (UIE) Department of Computer Science and Engineering (CSE) Difference between DELETE, DROP and TRUNCATE DELETE DROP TRUNCATE 1. It is a DML command. 1. It is a DDL command. 1. It is a DDL command. 2. It is used to delete rows or records based on conditions specified in the WHERE clause. 2. It is used to delete the entire table along with its schema and structure respectively. 2. It is used to delete the entire records of a table without affecting the schema of the table. 3. If the WHERE clause is not specified with conditions it deletes all the records of the table. 3. There is no WHERE clause. 3. There is no WHERE clause. 4. It is a DML command. As a result, the operation can be rolled back. 4. It is a DDL command. As a result, the changes cannot be rolled back or undone. 4. It is a DDL command. As a result, the changes cannot be rolled back or undone. 5. It scans every row before deleting making it slower and time-consuming. 5. It is faster and time-saving. 5. It is faster than DELETE in execution because it does not scan every row before deleting which makes it the least time-consuming. 6. Syntax: DELETE FROM TABLE Table_Name WHERE [CONDITIONS]; 6. Syntax: DROP TABLE Table_Name; 6. Syntax: TRUNCATE TABLE Table_Name;
  • 104. University Institute of Engineering (UIE) Department of Computer Science and Engineering (CSE) UPDATE COMMAND Purpose:- The Update statement updates columns in the existing table’s rows with new values. The Set clause indicates which column data should be modified and the new valued they should hold. Syntax:- Updating Specific Records Update <table name> set <col name1>=<expression1>, <col name2>=<expression2> where <condition>; Updating All The Records Update <table name> set <col name1>=<expression1>, <col name2>=<expression2>; Example:- Update STUDENT set Branch=’ECE’ where roll_no=101; Update STUDENT set Branch=’CSE’;
  • 105. University Institute of Engineering (UIE) Department of Computer Science and Engineering (CSE) DATA CONTROL LANGUAGE (DCL) This component of the SQL language is used to create privileges to allow users access to, and manipulation of, the database. There are two main commands: GRANT  to grant a privilege to a user REVOKE  to revoke (remove) a privilege from a user.
  • 106. University Institute of Engineering (UIE) Department of Computer Science and Engineering (CSE) FAQ 1.Define DBMS? List Database system Applications. 2. Discuss Database Administrator’s responsibilities. 3. What do you understand by dimension and attribute? 4. What is a fact & a fact table? 5. List out few common mistakes encountered during Data Modelling? 6. What do you understand by Data Modelling? 7. Explain your understanding of different data models?
  • 107. University Institute of Engineering (UIE) Department of Computer Science and Engineering (CSE) References • OTHER REFRENCES • ER Diagram: Entity Relationship Diagram Model | DBMS Example (guru99.com) • ER Diagram Representation - Tutorialspoint • Entity Relationship Diagram - ER Diagram in DBMS (beginnersbook.com) • http://nptel.ac.in/courses/Webcourse-contents/IISc- BANG/notused/IISc/New%20Rajaram%20pdfs/module8.pdf • http://ecomputernotes.com/fundamental/what-is-a-database/type-of-data-models • https://beginnersbook.com/2015/04/data-models-in-dbms/ • http://www.odbms.org/wp- content/uploads/2013/11/Data_Modeling_ConcepttoDBMS.pdf SUGGESTED BOOK REFERENCES • Ramez Elmasri and Shamkant B. Navathe,“Fundamentals of Database System”, The Benjamin / Cummings Publishing Co. • Korth and Silberschatz Abraham, “Database SystemConcepts”, McGraw Hall. • Pratt,”DBMS”, Cengage Learning.
  • 108. University Institute of Engineering (UIE) 113 Database Management System CO Number Title Level CO1 To perceive the significance and implementation of a commercial relational database system (Oracle) by writing SQL using the system. Remember CO2 To understand the relational database theory, and be able to write relational algebra expressions for queries Understand CO3 To identify the basic issues of transaction processing and concurrency control and find out its solutions. Analysis and application Course Outcome Will be covered in this lecture Department of Computer Science and Engineering (CSE)
  • 109. University Institute of Engineering (UIE) Department of Computer Science and Engineering (CSE) Contents of the Syllabus 114 UNIT-I [10h] Overview of Databases: Database concepts, DBMS, Data Base System Architecture (Three Level ANSI-SPARC Architecture), Advantages and Disadvantages of DBMS, Data Independence, DBA and Responsibilities of DBA, Relational Data Structure, Keys, Relations, Attributes, Schema and Instances, Referential integrity, Entity integrity. Data Models: Relational Model, Network Model, Hierarchical Model, ER Model: Design, issues, Mapping constraints, ER diagram, Comparison of Models. Relational Algebra & Relational Calculus: Introduction, Syntax, Semantics, Additional operators, Grouping and Ungrouping, Relational comparisons, Tuple Calculus, Domain Calculus, Calculus Vs Algebra, Computational capabilities. UNIT-II [10h] Functional dependencies and Normalization: Functional dependencies, Decomposition, Full Functional Dependency (FFD), Transitive Dependency (TD), Join Dependency (JD), Multi-valued Dependency (MVD), Normal Forms (1NF, 2NF, 3NF, BCNF), De-normalization. Database Security: Introduction, Threats, Counter Measures. Control Structures: Introduction to conditional control, Iterative control and sequential control statements, Cursors, Views. Department of Computer Science and Engineering (CSE)
  • 110. University Institute of Engineering (UIE) Department of Computer Science and Engineering (CSE) Contents of the Syllabus 115 UNIT-III [10h] Package, Procedures and Triggers: Parts of procedures, Parameter modes, Advantages of procedures, Syntax for creating triggers, Types of triggers, package specification and package body, developing a package, Bodiless package, Advantages of packages. Transaction Management and Concurrency Control: Introduction to Transaction Processing, Properties of Transactions, Serializability and Recoverability, Need for Concurrency Control, Locking Techniques, Time Stamping Methods, Optimistic Techniques and Granularity of Data items. Database Recovery of database: Introduction, Need for Recovery, Types of errors, Recovery Techniques. Department of Computer Science and Engineering (CSE)
  • 111. University Institute of Engineering (UIE) Department of Computer Science and Engineering (CSE) 116 Chapter 1.3 (Relational Algebra & Relational Calculus) Relational Algebra & Relational Calculus: Introduction, Syntax, Semantics, Additional operators, Grouping and Ungrouping, Relational comparisons, Tuple Calculus, Domain Calculus, Calculus vs Algebra, Computational capabilities.
  • 112. University Institute of Engineering (UIE) Department of Computer Science and Engineering (CSE) Learning Objective • To study relational algebra concepts, selection ,projection ,relational calculus which helps in understanding queries • Fundamentals operations on Relational Algebra • Tuple and Domain Relational Calculus
  • 113. University Institute of Engineering (UIE) Department of Computer Science and Engineering (CSE) Learning Outcome • Apply relational database theory, and be able to write relational algebra expressions for queries • Utilize the knowledge of basics of SQL and construct queries using SQL • Understanding relational algebra operators including extended operators
  • 114. University Institute of Engineering (UIE) Department of Computer Science and Engineering (CSE) Introduction • Relational algebra – Basic set of operations for the relational model – More operational (procedural), very useful for representing execution plans. • Relational calculus – Higher-level declarative language for specifying relational queries – Lets users describe what they want, rather than how to compute it: Non-operational, declarative.
  • 115. University Institute of Engineering (UIE) Department of Computer Science and Engineering (CSE) Relational Algebra • Relational algebra operations work on one or more relations to define another relation without changing the original relations. • Both operands and results are relations, so output from one operation can become input to another operation. • Allows expressions to be nested, just as in arithmetic. This property is called closure. • Five basic operations in relational algebra: Selection, Projection, Cartesian product, Union and Set Difference. • These perform most of the data retrieval operations needed. • Also have Join, Intersection, and Division operations, which can be expressed in terms of 5 basic operations.
  • 116. University Institute of Engineering (UIE) Department of Computer Science and Engineering (CSE) Relational Algebra • Basic operations: – Selection ( ) Selects a subset of rows from relation. – Projection ( ) Deletes unwanted columns from relation. – Cross-product ( ) Allows us to combine two relations. – Set-difference ( ) Tuples in reln. 1, but not in reln. 2. – Union ( ) Tuples in reln. 1 and in reln. 2. • Additional operations: – Intersection, join, division, renaming: Not essential, but (very!) useful.
  • 117. University Institute of Engineering (UIE) Department of Computer Science and Engineering (CSE) Relational Algebra Operations
  • 118. University Institute of Engineering (UIE) Department of Computer Science and Engineering (CSE) Relational Algebra Operations
  • 119. University Institute of Engineering (UIE) Department of Computer Science and Engineering (CSE) 124 Selection (or Restriction) • σpredicate (R) – Works on a single relation R and defines a relation that contains only those tuples (rows) of R that satisfy the specified condition (predicate). – Selects rows that satisfy selection condition. – No duplicates in result! – Schema of result identical to schema of input relation. – Selection is distributive over binary operators – Selection is commutative
  • 120. University Institute of Engineering (UIE) Department of Computer Science and Engineering (CSE) Example - Selection Restriction) • List all staff with a salary greater than £10,000. σsalary > 10000 (Staff)
  • 121. University Institute of Engineering (UIE) Department of Computer Science and Engineering (CSE) Projection • Πcol1, . . . , coln(R) – Works on a single relation R and defines a relation that contains a vertical subset of R, extracting the values of specified attributes and eliminating duplicates. – Deletes attributes that are not in projection list. – Schema of result contains exactly the fields in the projection list, with the same names that they had in the input relation. – Projection operator has to eliminate duplicates! Note: real systems typically don’t do duplicate elimination unless the user explicitly asks for it (by DISTINCT). Why not?
  • 122. University Institute of Engineering (UIE) Department of Computer Science and Engineering (CSE) Example - Projection • Produce a list of salaries for all staff, showing only staffNo, fName, lName, and salary details. ΠstaffNo, fName, lName, salary(Staff)
  • 123. University Institute of Engineering (UIE) Department of Computer Science and Engineering (CSE) Union • R ∪ S – Union of two relations R and S defines a relation that contains all the tuples of R, or S, or both R and S, duplicate tuples being eliminated. – R and S must be union-compatible. • If R and S have I and J tuples, respectively, union is obtained by concatenating them into one relation with a maximum of (I + J) tuples.
  • 124. University Institute of Engineering (UIE) Department of Computer Science and Engineering (CSE) Example - UNION • List all cities where there is either a branch office or a property for rent. Πcity(Branch) ∪ Πcity(PropertyForRent)
  • 125. University Institute of Engineering (UIE) Department of Computer Science and Engineering (CSE) Set Difference • R – S – Defines a relation consisting of the tuples that are in relation R, but not in S. – R and S must be union-compatible.
  • 126. University Institute of Engineering (UIE) Department of Computer Science and Engineering (CSE) Example - Set Difference • List all cities where there is a branch office but no properties for rent. Πcity(Branch) – Πcity(PropertyForRent)
  • 127. University Institute of Engineering (UIE) Department of Computer Science and Engineering (CSE) Intersection • R ∩ S – Defines a relation consisting of the set of all tuples that are in both R and S. – R and S must be union-compatible. • Expressed using basic operations: R ∩ S = R – (R – S)
  • 128. University Institute of Engineering (UIE) Department of Computer Science and Engineering (CSE) Example - Intersection • List all cities where there is both a branch office and at least one property for rent. Πcity(Branch) ∩ Πcity(PropertyForRent)
  • 129. University Institute of Engineering (UIE) Department of Computer Science and Engineering (CSE) Cartesian product • R X S – Defines a relation that is the concatenation of every tuple of relation “R with every tuple of relation S”
  • 130. University Institute of Engineering (UIE) Department of Computer Science and Engineering (CSE) 135 Example - Cartesian product • List the names and comments of all clients who have viewed a property for rent. (ΠclientNo, fName, lName(Client)) X (ΠclientNo, propertyNo, comment (Viewing)) Pearson Education © 2009
  • 131. University Institute of Engineering (UIE) Department of Computer Science and Engineering (CSE) 136 Example - Cartesian product and Selection • Use selection operation to extract those tuples where Client.clientNo = Viewing.clientNo. sClient.clientNo = Viewing.clientNo((ÕclientNo, fName, lName(Client)) Χ (ÕclientNo, propertyNo, comment(Viewing))) ● Cartesian product and Selection can be reduced to a single operation called a Join. Pearson Education © 2009
  • 132. University Institute of Engineering (UIE) Department of Computer Science and Engineering (CSE) 137 Join Operations • JOINs can be used to combine tables • Join is a derivative of Cartesian product. • Equivalent to performing a Selection, using join predicate as selection formula, over Cartesian product of the two operand relations. • One of the most difficult operations to implement efficiently in an RDBMS and one reason why RDBMSs have intrinsic performance problems. Pearson Education © 2009
  • 133. University Institute of Engineering (UIE) Department of Computer Science and Engineering (CSE) 138 Join Operations • Various forms of join operation – JOIN (Inner Join) : Return rows when there is at least one match in both tables – LEFT JOIN(Left Outer Join): Return all rows from the left table, even if there are no matches in the right table – RIGHT JOIN(Right Outer Join): Return all rows from the right table, even if there are no matches in the left table – FULL JOIN: Return rows when there is a match in one of the tables Pearson Education © 2009
  • 134. University Institute of Engineering (UIE) Department of Computer Science and Engineering (CSE) SQL INNER JOIN Syntax SELECT column_name(s) FROM table_name1 INNER JOIN table_name2 ON table_name1.column_name=table_name2.column_name INNER JOIN is the same as JOIN The word "INNER" is optional
  • 135. University Institute of Engineering (UIE) Department of Computer Science and Engineering (CSE) * Example - Inner Join
  • 136. University Institute of Engineering (UIE) Department of Computer Science and Engineering (CSE) Left Join
  • 137. University Institute of Engineering (UIE) Department of Computer Science and Engineering (CSE) Example - Left Join
  • 138. University Institute of Engineering (UIE) Department of Computer Science and Engineering (CSE) Right Join
  • 139. University Institute of Engineering (UIE) Department of Computer Science and Engineering (CSE) Example – Right Join
  • 140. University Institute of Engineering (UIE) Department of Computer Science and Engineering (CSE) Full Join
  • 141. University Institute of Engineering (UIE) Department of Computer Science and Engineering (CSE) Example – Full Join
  • 142. University Institute of Engineering (UIE) Department of Computer Science and Engineering (CSE) FAQ 1. How does Tuple-oriented relational calculus differ from domain- oriented relational calculus? 2. Define Relational Algebra and Relational Calculus 3. What is degree of a Relation? 4. What is a Relation Schema and a Relation? 5. List various Operators used in Relational Algebra and Calculus 6. Solve the given by relational algebra. The Relations are : • Emp(empno,ename,sal,job,comm,deptno) • Dept (deptno,dname,dloc) • Create a query to list unique jobs that are in deptno 30 and include the location of department 30 in output
  • 143. University Institute of Engineering (UIE) Department of Computer Science and Engineering (CSE) References OTHER REFRENCES • https://cs.uwaterloo.ca/~tozsu/courses/CS348/notes/4b-calculus-handout-notes.pdf • http://www.ccs.neu.edu/home/kathleen/classes/cs3200/4-RAAndRC.pdf • https://www2.cs.sfu.ca/CourseCentral/354/louie/Chap3_practice.pdf • http://www.nyu.edu/classes/jcf/CSCI-GA.2433- 001_fa11/slides/session5/RelationalAlgebra-RelationalCalculus-SQL.pdf • https://blog.inf.ed.ac.uk/da15/files/2015/01/inf1-da-15-t3.pdf • DatabaseSystemConceptsbySudarshan,Korth(McGraw-HillEducation) • FundamentalsofDatabaseSystemByElmasari&Navathe-PearsonEducation • http://ecomputernotes.com/database-system/rdbms • https://www.tutorialspoint.com/sql/sql-rdbms-concepts.htm • https://www.studytonight.com/dbms/rdbms-concept SUGGESTED BOOK REFERENCES • Ramez Elmasri and Shamkant B. Navathe,“Fundamentals of Database System”, The Benjamin / Cummings Publishing Co. • Korth and Silberschatz Abraham, “Database SystemConcepts”, McGraw Hall. • Pratt,”DBMS”, Cengage Learning.
  • 144. University Institute of Engineering (UIE) 150 Database Management System CO Number Title Level CO1 To perceive the significance and implementation of a commercial relational database system (Oracle) by writing SQL using the system. Remember CO2 To understand the relational database theory, and be able to write relational algebra expressions for queries Understand CO3 To identify the basic issues of transaction processing and concurrency control and find out its solutions. Analysis and application Course Outcome Will be covered in this lecture Department of Computer Science and Engineering (CSE)
  • 145. University Institute of Engineering (UIE) Department of Computer Science and Engineering (CSE) Contents of the Syllabus 151 UNIT-I [10h] Overview of Databases: Database concepts, DBMS, Data Base System Architecture (Three Level ANSI-SPARC Architecture), Advantages and Disadvantages of DBMS, Data Independence, DBA and Responsibilities of DBA, Relational Data Structure, Keys, Relations, Attributes, Schema and Instances, Referential integrity, Entity integrity. Data Models: Relational Model, Network Model, Hierarchical Model, ER Model: Design, issues, Mapping constraints, ER diagram, Comparison of Models. Relational Algebra & Relational Calculus: Introduction, Syntax, Semantics, Additional operators, Grouping and Ungrouping, Relational comparisons, Tuple Calculus, Domain Calculus, Calculus Vs Algebra, Computational capabilities. UNIT-II [10h] Functional dependencies and Normalization: Functional dependencies, Decomposition, Full Functional Dependency (FFD), Transitive Dependency (TD), Join Dependency (JD), Multi-valued Dependency (MVD), Normal Forms (1NF, 2NF, 3NF, BCNF), De-normalization. Database Security: Introduction, Threats, Counter Measures. Control Structures: Introduction to conditional control, Iterative control and sequential control statements, Cursors, Views. Department of Computer Science and Engineering (CSE)
  • 146. University Institute of Engineering (UIE) Department of Computer Science and Engineering (CSE) Contents of the Syllabus 152 UNIT-III [10h] Package, Procedures and Triggers: Parts of procedures, Parameter modes, Advantages of procedures, Syntax for creating triggers, Types of triggers, package specification and package body, developing a package, Bodiless package, Advantages of packages. Transaction Management and Concurrency Control: Introduction to Transaction Processing, Properties of Transactions, Serializability and Recoverability, Need for Concurrency Control, Locking Techniques, Time Stamping Methods, Optimistic Techniques and Granularity of Data items. Database Recovery of database: Introduction, Need for Recovery, Types of errors, Recovery Techniques. Department of Computer Science and Engineering (CSE)
  • 147. University Institute of Engineering (UIE) Department of Computer Science and Engineering (CSE) 153 Chapter 3 (Relational Algebra & Relational Calculus) Relational Algebra & Relational Calculus: Introduction, Syntax, Semantics, Additional operators, Grouping and Ungrouping, Relational comparisons, Tuple Calculus, Domain Calculus, Calculus vs Algebra, Computational capabilities.
  • 148. University Institute of Engineering (UIE) Department of Computer Science and Engineering (CSE) Learning Objective • To study relational algebra concepts, selection ,projection ,relational calculus which helps in understanding queries • Fundamentals operations on Relational Algebra • Tuple and Domain Relational Calculus
  • 149. University Institute of Engineering (UIE) Department of Computer Science and Engineering (CSE) Learning Outcome • Apply relational database theory, and be able to write relational algebra expressions for queries • Utilize the knowledge of basics of SQL and construct queries using SQL • Understanding relational algebra operators including extended operators
  • 150. University Institute of Engineering (UIE) Department of Computer Science and Engineering (CSE) Relational Calculus • There are two versions of the relational calculus: – Tuple relational calculus (TRC) – Domain relational calculus (DRC) • The calculus is non-procedural (‘declarative’) compared to the relational algebra • Calculus has variables, constants, comparison ops, logical connectives and quantifiers. – TRC: Variables range over (i.e., get bound to) tuples. – DRC: Variables range over domain elements (= field values). – Both TRC and DRC are simple subsets of first-order logic. • Expressions in the calculus are called formulas. An answer tuple is essentially an assignment of constants to variables that make the formula evaluate to true.
  • 151. University Institute of Engineering (UIE) Department of Computer Science and Engineering (CSE) • Relational Calculus • Relational Algebra is a PROCEDURAL LANGUAGE ⮚ we must explicitly provide a sequence of operations to • generate a desired output result • Relational Calculus is a DECLARATIVE LANGUAGE ⮚ we specify what to retrieve, not how to retrieve it
  • 152. University Institute of Engineering (UIE) Department of Computer Science and Engineering (CSE) What is Relational Calculus? • It is a formal language based upon predicate calculus • It allows you to express the set of tuples you want from a database using a formula • Expressions in the calculus are called formula • An answer tuple is essentially an assignment of constants to vari ables that make the formula evaluate to true.
  • 153. University Institute of Engineering (UIE) Department of Computer Science and Engineering (CSE) Declarative ~ Non-Procedural Two variants of relational calculus are • TUPLE Relational Calculus • Domain Relational Calculus • Calculus has variables, constants, comparison ops, logical connectives and quantifiers. • TRC: Variables range over (i.e., get bound to) tuples. • DRC: Variables range over domain elements (= field values)
  • 154. University Institute of Engineering (UIE) Department of Computer Science and Engineering (CSE) RELATIONAL CALCULUS • If a retrieval can be specified in the relational calculus, it can be specified in the relational algebra, and vise versa →expressive power of the languages is identical • A query language L is Relationally complete if L can express any query that can be expressed in the relational calculus
  • 155. University Institute of Engineering (UIE) Department of Computer Science and Engineering (CSE) Relational Calculus • TRC and DRC are semantically similar • In TRC, tuples share an equal status as variables, and field referencing can be used to select tuple parts • In DRC, formal variables are explicit
  • 156. University Institute of Engineering (UIE) Department of Computer Science and Engineering (CSE) Tuple Relational Calculus • Query: {T | P(T)} – T is tuple variable – P(T) is a formula that describes T • Result, the set of all tuples t for which P(t) evaluates True. – Find all sailors with a rating above 7. – • Atomic formula – – R.a op S.b , op is one of – R.a op constant
  • 157. University Institute of Engineering (UIE) Department of Computer Science and Engineering (CSE) Tuple Relational Calculus • A logical language with variables ranging over tuples: { T | Cond } – Return all tuples T that satisfy the condition Cond. • { T | R(T) }: returns all tuples T such that T is a tuple in relation R. • { T.name | F ACULT Y (T) AND T.DeptId = ‘CS’ }. returns the values of name field of all faculty tuples with the value ’CS’ in their department id field. – The variable T is said to be free since it is not bound by a quantifier (for all, exists). – The result of this statement is a relation (or a set of tuples) that correspond to all possible ways to satisfy this statement. – Find all possible instances of T that make this statement true.
  • 158. University Institute of Engineering (UIE) Department of Computer Science and Engineering (CSE) TUPLE RELATIONAL CALCULUS • Query: {T|P(T)} • T is tuple variable • P(T) is a formula that describes T Result: the set of all tuples t for which P(t) evaluates Tr ue. ⮚ Find all sailors with a rating above 7.
  • 159. University Institute of Engineering (UIE) Department of Computer Science and Engineering (CSE) OPERATIONS in Tuple Relational Calculus • ∧ - AND • ∨ - OR • ¬ - NOT • ∃x – there exists x • ∀x – for all x Note: General power of 1st order predicate calculus – allow more flexible expression formats
  • 160. University Institute of Engineering (UIE) Department of Computer Science and Engineering (CSE) TUPLE RELATIONAL CALCULUS
  • 161. University Institute of Engineering (UIE) Department of Computer Science and Engineering (CSE) TUPLE RELATIONAL CALCULUS
  • 162. University Institute of Engineering (UIE) Department of Computer Science and Engineering (CSE) JOINS IN THE TUPLE RELATIONAL CALCULUS
  • 163. University Institute of Engineering (UIE) Department of Computer Science and Engineering (CSE) Examples Consider relations for queries: • Relation 1:
  • 164. University Institute of Engineering (UIE) Department of Computer Science and Engineering (CSE) Relation 2: Relation 3:
  • 165. University Institute of Engineering (UIE) Department of Computer Science and Engineering (CSE) 1. Find the loan number, branch, amount of loans of greater than or equal to 10000 amount {t| t ∈ loan ∧ t[amount]>=10000} 2. Find the loan number for each loan of an amount greater or equal to 10000. {t| ∃ s ∈ loan(t[loan number] = s[loan number] ∧ s[amount]>=10000)} 3. Find the names of all customers who have a loan and an account at the bank. {t | ∃ s ∈ borrower( t[customer-name] = s[customer-name]) ∧ ∃ u ∈ depositor( t[customer-name] = u[customer-name])}
  • 166. University Institute of Engineering (UIE) Department of Computer Science and Engineering (CSE) 4. Find the names of all customers having a loan at the “ABC” branch. {t | ∃ s ∈ borrower(t[customer-name] = s[customer-name] ∧ ∃ u ∈ loan(u[branch-name] = “ABC” ∧ u[loan-number] = s[loan-number]))}
  • 167. University Institute of Engineering (UIE) Department of Computer Science and Engineering (CSE) Domain Relational Calculus • Query has the form: ❖ Answer includes all tuples that make the formula be true. Formula is recursively defined, starting with simple atomic formulas (getting tuples from relations or making comparisons of values), and building bigger and better formulas using the logical connectives.
  • 168. University Institute of Engineering (UIE) Department of Computer Science and Engineering (CSE) Domain Relational Calculus
  • 169. University Institute of Engineering (UIE) Department of Computer Science and Engineering (CSE) Domain Relational Calculus • Query has the form: { <x1,x2….xn>| p(<x1,x2….xn>)} • Domain Variable – ranges over the values in the domain of some attribute or is a constant • Example: If the domain variable x1 maps to attribute - Name char(20) then x1 ranges over all strings that are 20 characters long Not just the strings values in the relation’s attribute • Answer includes all tuples that make the formula p() true.
  • 170. University Institute of Engineering (UIE) Department of Computer Science and Engineering (CSE) DOMAIN RELATIONAL CALCULUS
  • 171. University Institute of Engineering (UIE) Department of Computer Science and Engineering (CSE) DRC Formulas • Atomic Formulas 1. <x1,x2,…xn>∈ Relation where Relation is a relation with n attributes 2. X operation Y 3. X operation constant Where operation is an operator in the set { , = , ≤, ≥, ≠ } • Recursive definition of a Formula: 1. An atomic formula 2. ¬p, p∧q, p∨q, where p and q are formulas 3. ∃X(p(X)), where variable X is free in p(X) 4. ∀X(p(X)), where variable X is free in p(X) The use of quantifiers ∃X and ∀X is said to bind X A variable that is not bound is free.
  • 172. University Institute of Engineering (UIE) Department of Computer Science and Engineering (CSE) Quantifiers: ∀x and ∃x • Variable x is said to be subordinate to the quantifier You are restricting (or binding) the value of the variable x to set S • The set S is known as the range of the quantifier • ∀x predicate true for all elements in set S • ∃x predicate true for at least 1 element in set S
  • 173. University Institute of Engineering (UIE) Department of Computer Science and Engineering (CSE) Examples 1. Find the loan number, branch, amount of loans of greater than or equal to 100 amount. {≺l, b, a≻ | ≺l, b, a≻ ∈ loan ∧ (a ≥ 100)} 2. Find the loan number for each loan of an amount greater or equal to 150. {≺l≻ | ∃ b, a (≺l, b, a≻ ∈ loan ∧ (a ≥ 150)} 3. Find the names of all customers having a loan at the “Main” branch and find the loan amount . {≺c, a≻ | ∃ l (≺c, l≻ ∈ borrower ∧ ∃ b (≺l, b, a≻ ∈ loan ∧ (b = “Main”)))}
  • 174. University Institute of Engineering (UIE) Department of Computer Science and Engineering (CSE) Relational Calculus: Summary • Relational calculus is non-operational ⮚ Users define queries in terms of what they want, not in terms of how to compute it. (Declarativeness.) • Algebra and safe calculus have the same expressive power, leading to the notion of relational completeness. • Relational calculus had big influence on the design of SQL and Query-by-Example
  • 175. University Institute of Engineering (UIE) Department of Computer Science and Engineering (CSE) Summary • Relational algebra is more operational; useful as internal representation for query evaluation plans. • Relational calculus is non-operational, and users define queries in terms of what they want, not in terms of how to compute it. (Declarativeness.) • Algebra and safe calculus have same expressive power, leading to the notion of relational completeness.
  • 176. University Institute of Engineering (UIE) Department of Computer Science and Engineering (CSE) FAQ 1. How does Tuple-oriented relational calculus differ from domain-oriented relational calculus? 2. Define Relational Algebra and Relational Calculus 3. What is degree of a Relation? 4. What is a Relation Schema and a Relation? 5. List various Operators used in Relational Algebra and Calculus
  • 177. University Institute of Engineering (UIE) Department of Computer Science and Engineering (CSE) References OTHER REFRENCES • https://cs.uwaterloo.ca/~tozsu/courses/CS348/notes/4b-calculus-handout-notes.pdf • http://www.ccs.neu.edu/home/kathleen/classes/cs3200/4-RAAndRC.pdf • https://www2.cs.sfu.ca/CourseCentral/354/louie/Chap3_practice.pdf • http://www.nyu.edu/classes/jcf/CSCI-GA.2433-001_fa11/slides/session5/RelationalAlgebra- RelationalCalculus-SQL.pdf • https://blog.inf.ed.ac.uk/da15/files/2015/01/inf1-da-15-t3.pdf • DatabaseSystemConceptsbySudarshan,Korth(McGraw-HillEducation) • FundamentalsofDatabaseSystemByElmasari&Navathe-PearsonEducation • http://ecomputernotes.com/database-system/rdbms • https://www.tutorialspoint.com/sql/sql-rdbms-concepts.htm • https://www.studytonight.com/dbms/rdbms-concept SUGGESTED BOOK REFERENCES • Ramez Elmasri and Shamkant B. Navathe,“Fundamentals of Database System”, The Benjamin / Cummings Publishing Co. • Korth and Silberschatz Abraham, “Database SystemConcepts”, McGraw Hall. • Pratt,”DBMS”, Cengage Learning.