Week 1 - 4 Summary Slides
Week 1 - 4 Summary Slides
Comparison
Levels of
Abstraction
Database Engine
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
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
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 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
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
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
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
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
Week-3
Module 14
User-Defined Types - using create type statement
Module 15
Domains - using create domain statement
Week-3
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
{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(¬).
{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
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
one-to-many relationship
many-to-many relationship