0% found this document useful (0 votes)
6 views

Week 1 - 4 Summary Slides

dbms
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

Week 1 - 4 Summary Slides

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

Week-1

Comparison

Levels of
Abstraction

Database Engine

Database Management Systems


Summary : Week-1
Comparison PPD

Week-1
Parameter File Handling via Python DBMS
Scalability with re- Very difficult to handle insert, update and In-built features to provide high scalability for
spect to querying of records a large number of records
Comparison amount of data
Levels of Scalability with re- Extremely difficult to change the structure of Adding or removing attributes can be done
Abstraction spect to changes records as in the case of adding or removing seamlessly using simple SQL queries
Database Engine
in structure attributes
Time of execution In seconds In milliseconds
Persistence Data processed using temporary data struc- Data persistence is ensured via automatic, sys-
tures have to be manually updated to the file tem induced mechanisms
Robustness Ensuring robustness of data has to be done Backup, recovery and restore need minimum
manually manual intervention
Security Difficult to implement in Python (Security at User-specific access at database level
OS level)
Programmer’s Most file access operations involve extensive Standard and simple built-in queries reduce the
productivity coding to ensure persistence, robustness and effort involved in coding thereby increasing a
security of data programmer’s throughput
Arithmetic opera- Easy to do arithmetic computations Limited set of arithmetic operations are avail-
tions able
Costs Low costs for hardware, software and human High costs for hardware, software and human
resources resources
Levels of Abstraction

Week-1
Physical level: Describes how a record is stored (e.g. blocks of storage)
Logical level: Describes data stored in a database, and the relationships among the
Comparison

Levels of
data fields (attributes, data types of attributes etc.)
Abstraction View level: Application programs hide details of data types; it also hides information
Database Engine
for security purposes (user interfaces)
Database Engine

Week-1

Storage manager
Comparison
Provides the interface between the low-level data stored in the database and the
Levels of
application programs and queries submitted to the system
Abstraction
Interact with the OS file manager
Database Engine
Efficient storing, retrieving and updating of data

Query Processing
Parsing and translation →
Optimization → Evaluation

Figure: Query Processing


Database Engine (cont..)

Week-1

Transaction Management
Comparison A transaction is a collection of operations that performs a single logical function
Levels of in a database application
Abstraction
Transaction-management component - ensures that the database remains in a
Database Engine
consistent state despite system failures and transaction failures.
Concurrency-control manager - controls the interaction among the concurrent
transactions
Week-3

Module 6

Module 6

Module 7

Module 9
Database Management Systems
Module 10 Summary : Week-2

January 26, 2022


Module 6 Recap

Week-3 Attributes types, schema and instance, keys, relational query languages
Attribute Types - The set of allowed values for each attribute is called the domain
Module 6 of the attribute. i.e. Alphanumeric string, Alpha string, Date, number etc.
Schema - R = (A1, A2, · · · , An) is a relation schema.
Module 6

Module 7

Module 9 A1, A2, · · ·, An are attributes


Module 10 Instances: The collection of information stored in the database at a particular
moment is called an instance of the database.
Let K R, where R is the set of attributes in the relation.
K is a super key of R if values for K are sufficient to identify a unique tuple of each
possible relation r(R).
Super key K is a candidate key if K is minimal.
One of the candidate keys is selected to be the primary key.
A surrogate key (or synthetic key) in a database is a unique identifier for either an
entity in the modeled world or an object in the database.
Module 6 Recap (Cont.)

Week-3 keys, relational query languages


Secondary / Alternate Key: candidate keys other than primary key.
Module 6
Simple key: Consists of a single attribute.
Module 6

Module 7
Composite key: Consists of more than one attribute to uniquely identify each tuples
Module 9 in a relation.
Module 10 Foreign key: Value in one relation must appear in another.
Compound key: consists of more than one attribute to uniquely identify an entity
occurrence.
Relational Query language:
Procedural programming: requires that the programmer tell the computer what to
do.That is, how to get the output for the range of required inputs.
Declarative programming: requires a more descriptive style ◦ The programmer must
know what relationships hold between various entities
Module 7 Recap

Week-3
Relational operators
Module 6
select operation: selection of rows(tuples). i.e: σD>5 (r )
Module 6 Project operation: selection of columns (Attributes). i.e. πA,C (r )
Module 7
Union: union of two relations. i.e. r ∪ s
Module 9

Module 10 Difference: Set difference of two relations. i.e. r − s


Intersection: Set intersection of two relations. i.e. r ∩ s
Cartesian Product: Joining two relations – Cartesian-product. i.e. r × s
Natural Join: natural join operation on two relations matches tuples whose values are
the same on all attribute names that are common to both relations. i.e. r ▷◁ s
Module 8 Recap

Week-3
History of SQL, DDL, DML: Query structure
Module 6
History of SQL
Module 6 Data Definition Language (DDL): The SQL DDL provides commands for defining
Module 7 relation schemas, deleting relations, and modifying relation schema. i.e. CREATE
Module 9
TABLE, DROP TABLE, ALTER etc.
Module 10
Data Manipulation Language (DML):The SQL DML provides the ability to query
information from the database and to insert tuples into, delete tuples from, and
modify tuples in the database. i.e. update, insert, delete etc.
Basic SQL structure: SELECT A1,A2,..,An FROM r1,r2,.., rm WHERE P
Select clauseThe select clause lists the attributes desired in the result of a query.
Where clause: The where clause specifies conditions that the result must satisfy.
From clause: The from clause lists the relations involved in the query.
Module 9 Recap

Week-3
Additional Basic Operations
Cartesian Product: The Cartesian product instructor X teaches. SQL query is :
Module 6

Module 6
select *
Module 7 from instructor, teaches
Module 9

Module 10 it generates every possible instructor-teaches pair, with all attributes from both
relations.
Rename AS Operation:The SQL allows renaming relations and attributes using the
as clause. i.e. old name as new name
String Operation: SQL includes a string-matching operator for comparisons on
character strings. The operator like uses patterns that are described using two special
characters:
percent ( % ). The % character matches any substring
underscore ( ). The character matches any character
Order By: We may specify desc for descending order or asc for ascending order, for
each attribute; ascending order is the default.i.e order by name desc
Module 9 Recap (Cont.)

Week-3
Additional Basic Operations
Module 6
Select top/ Fetch: The Select Top clause is used to specify the number of records to
Module 6
return. i.e
Module 7 select top 10 distinct name from instructor
Module 9

Module 10
Oracle uses fetch first n rows only and rownum
select distinct name from instructor
order by name
fetch first 10 rows only

Where Clause Predicate: SQL includes a between comparison operator, Tuple


comparison.
IN operator: The in operator allows you to specify multiple values in a where clause.
Duplicates:In relations with duplicates, SQL can define how many copies of tuples
appear in the result. Multiset versions of some relational algebra operators.
Module 10 Recap

Week-3
set operations, null values and aggregation
Module 6
Set Operations: union, intersect, except
Module 6
Each of the above operations automatically eliminates duplicates.
Module 7
o retain all duplicates use the corresponding multiset versions union all, intersect all, and
Module 9 except all,
Module 10 Null Values: null signifies an unknown value or that a value does not exist.
Aggregate Functions:
avg: return average value
min: return min value
max: return max value
sum: return sum of values
count: return number of values
Module 10 Recap (Cont.)

Week-3

Group By:
Module 6
The attribute or attributes given in the group by clause are used to form groups.
Module 6
Tuples with the same value on all attributes in the group by clause are placed in one
Module 7
group
Module 9 Having: predicates in the having clause are applied after the formation of groups.
Module 10
Null Values All aggregate operations except count(*) ignore tuples with null values
on the aggregated attributes.
Week-3

Module 11

Module 12

Module 13

Module 14
Database Management Systems
Module 15 Summary : Week-3

January 26, 2022


Module 11

Week-3 Various basic SQL features through example workout


select distinct - removing the duplicates
Module 11
select all - (duplicate retention is the default)
Module 12

Module 13
Cartesian Product
Module 14 Rename AS Operation
Module 15
where: AND and OR
String Operations - like with % and
order by - ASC and DESC
in Operator
Set Operations
union - union removes all duplicates.
Use union all instead of union to retain the duplicates
intersect
except
Aggregate functions - avg, min, max, count, sum
Module 12

Week-3
Nested Subqueries
Module 11
A subquery is a select-from-where expression that is nested within another query
Module 12
Subqueries in the where clause
Module 13
Typical use of subqueries is to perform tests:
For set membership - using in
Module 14
For set comparisons - using some, any, all, exists, not exists and unique
Module 15
Subqueries in the from clause
The clause provides a way of defining a temporary relation whose definition is available
only to the query in which the with clause occurs
Subqueries in the select clause
Using - scalar subquery is one which is used where a single value is expected
Modification of the Database
Deletion of tuples from a given relation - delete from
Insertion of new tuples into a given relation - insert into
Updating of values in some tuples in a given relation - update
Module 13

Week-3
Join Expressions
Module 11 Join operations take two relations and return as a result another relation
Module 12

Module 13
Types of Join between Relations:
Module 14
Cross Join - returns the Cartesian product of rows from tables in the join
Module 15
Inner join - joins two table on the basis of the column which is explicitly specified in the ON
clause with a given condition using a comparison operator
Equi-join - condition containing an equality (=) operator
Natural join - joins two tables based on same attribute name and compatible datatypes
Outer join - computes the join and then adds tuples from one relation that does not match
tuples in the other relation to the result of the join - uses null values
Left outer join
Right outer join
Full outer join
Self-join - a table is joined with itself
Module 13 (Cont.)

Week-3
Views
Module 11 A view provides a mechanism to hide certain data from the view of certain users
Module 12

Module 13 Any relation that is not of the conceptual model but is made visible to a user as a“virtual
Module 14 relation” is called a view.
Module 15
Defining a view using the create view statement
Views defined using other views
Materializing a view - create a physical table containing all the tuples in the result of the
query defining the view
Module 14

Week-3

Integrity Constraints - Guard against accidental damage to the database, by ensuring


Module 11 that authorized changes to the database do not result in a loss of data consistency
Module 12

Module 13 Integrity Constraints on a Single Relation


Module 14
not null
Module 15
primary key
unique
check(P), where P is a predicate

Referential Integrity - Ensures that a value that appears in one relation for a given set of
attributes also appears for a certain set of attributes in another relation

Cascading actions in referential integrity


on delete cascade, on update cascade
Module 14 (Cont.)

Week-3

Built-in Data Types in SQL - such as date, time, timestamp, interval


Module 11

Module 12 Index creation - using create index statement


Module 13

Module 14
User-Defined Types - using create type statement
Module 15
Domains - using create domain statement

Types and domains are similar

Domains can have constraints, such as not null

Authorization - using grant and revoke statement

Roles - using create role statement


Module 15

Week-3

SQL functions - using create function statement


Module 11
Table-valued functions - can return a relation as a result
Module 12

Module 13
SQL procedures - using create procedure statement
Module 14

Module 15
Language constructs for procedures and functions - while loop, repeat loop, for loop,
if-then-else, case
Trigger - a set of actions that are performed in response to an insert, update, or delete
operation on a specified table

Before triggers and after triggers


Row level and statement level triggers
Triggering events and actions in SQL
Triggering event can be an insert, delete or update
Database Management Systems
Week 4 Summary

January 26, 2022


TRC

TRC is a nonprocedural query language, where each query is of the form

{t | P(t)}
where t = resulting tuples,
P(t) = known as predicate and these are the conditions that are used to fetch t.
P(t) may have various conditions logically combined with OR (∨), AND (∧), NOT(¬).

It also uses quantifiers:


∃t ∈ r (Q(t)) = ”there exists” a tuple in t in relation r such that predicate Q(t) is true.
∀t ∈ r (Q(t)) = Q(t) is true “for all” tuples in relation r.

{P | ∃S ∈ Students(S.CGPA > 8 ∧ P.name = S.sname ∧ P.age = S.age)} : returns the name and
age of students with a CGPA above 8.
DRC

{< x1 , x2 , . . . , xn > |P(x1 , x2 , . . . , xn )}


x1 , x2 , . . . , xn represent domain variables
P represents a formula similar to that of the predicate calculus
Name Age Marks Subject
David 23 78 Maths
Matthew 29 54 English
Anand 22 89 JAVA
Mitchel 21 56 Maths
Shaun 26 92 Maths

Relation Students
{< a, b >| ∃a, b, c, d(< a, b, c, d >∈ students ∧ c > 75)} : returns the name and age
of students having marks above 75.
Note: You have to mention the domain variables in the same order as given in the table.
Q1

Name Age Marks Subject Name Sports Awards Points


David 23 78 Maths David Cricket 2 67
Matthew 29 54 English Matthew Football 4 90
Anand 22 89 JAVA Anand Cricket 5 80
Mitchel 21 56 Maths Mitchel Tennis 8 70
Shaun 26 92 Maths Shaun Hockey 3 75

Relation Students Relation Activity


Q). Write down the RA, TRC and DRC expressions which will return the names of students
whose age is greater than 25, or who are enrolled in Maths.
RA: ΠName (σage>25∨subject=”Maths” (Students))
TRC: {t | ∃s ∈ students(s.age > 25 ∨ s.subject = ”Maths” ∧ t.name = s.name)}

{t.name | t ∈ students ∧ s.age > 25 ∨ s.subject = ”Maths”)}


DRC: {< a >| ∃b, c, d(< a, b, c, d >∈ students ∧ b > 25 ∨ d = ”Maths”)}
Q2

Name Age Marks Subject Name Sports Awards Points


David 23 78 Maths David Cricket 2 67
Matthew 29 54 English Matthew Football 4 90
Anand 22 89 JAVA Anand Cricket 5 80
Mitchel 21 56 Maths Mitchel Tennis 8 70
Shaun 26 92 Maths Shaun Hockey 3 75

Relation Students Relation Activity


Q). Write down the RA, TRC and DRC expressions which will return the names of students
along with sports, whose age is less than 25 and who have secured more than 75 marks.
RA: ΠName,Sports, (σage<25∧Marks>75 (Students ⋊
⋉ Activity ))
TRC: {t | ∃s ∈ students ∃a ∈ activity (s.name = a.name ∧ s.age < 25 ∧ s.marks >
75 ∧ t.name = s.name ∧ t.sports = a.sports)}
DRC: {< a, f >| ∃b, c, d(< a, b, c, d >∈ students ∧ b < 25 ∧ c > 75) ∧ ∃e, g , h(<
e, f , g , h >∈ activity ∧ a = e)}
Q3
Name Age Marks Subject Name Sports Awards Points
David 23 78 Maths David Cricket 2 67
Matthew 29 54 English Matthew Football 4 90
Anand 22 89 JAVA Anand Cricket 5 80
Mitchel 21 56 Maths Mitchel Tennis 8 70
Shaun 26 92 Maths Shaun Hockey 3 75

Relation Students Relation Activity


Q). Write down the RA, TRC and DRC expressions which will return the names of students
and sports played by the students whose age is less than 25 and have won more than 3
awards.
RA: ΠName,Sports, (σage<25∧awards>3 (Students ⋊
⋉ Activity ))
TRC: {t | ∃s ∈ students ∃a ∈ activity (s.name = a.name ∧ s.age < 25 ∧ a.awards >
3 ∧ t.name = s.name ∧ t.sports = a.sports)}
DRC: {< a, f >| ∃b, c, d(< a, b, c, d >∈ students ∧ b < 25) ∧ ∃e, g , h(< e, f , g , h >∈
activity ∧ g > 3 ∧ a = e)}
E-R Diagram
Please go through the tutorials.
Mapping Constraints

one-to-many relationship
many-to-many relationship

one-to-one relationship many-to-one relationship

Total and Partial Participation

Tutorial: Case study on E-R diagram 3/6


E-R diagrams symbols

Tutorial: Case study on E-R diagram 4/6

You might also like