Mod 1,2 Minor
Mod 1,2 Minor
Mod 1,2 Minor
1
Amity School of Engineering & Technology
Module-I Introduction
1. Concept and goals of DBMS,
2. Database Languages,
3. Database Users,
4. Database Abstraction.
5. Database architecture,
6. The Relational Data Model and
7. Relational Database Constraints,
8. Basic Concepts of ER Model,
9. Relationship sets,
10. Keys,
11. Mapping,
12. Design of ER Model
2
Amity School of Engineering & Technology
Pre-requisites:
• Knowledge about the raw data
3
Amity School of Engineering & Technology
Course Objectives:
• The objective of this course is to get students familiar with
Databases and their use.
4
Amity School of Engineering & Technology
5
Amity School of Engineering & Technology
Data Vs Information
Data: Raw fact, Unorganized, Unprocessed information
Exp: Marks /result of classes and school
6
Amity School of Engineering & Technology
Objectives
• Mass Storage large amount of data
• Remove Duplicates Remove
• Multiuser Access can be done by multiple user
• Protection Security for data access
7
Amity School of Engineering & Technology
Types of databases
• Centralized database One DB + Multiple users
• Distributed Database Multiple DB + Multiple users
• Personal Database Small DB+ Single used
• End user Database Application –based on the role
• Commercial Database User have to pay for accessing data
• Relational Database Data Table Row & column
Row Tuple , Column Attributes
• Cloud Database Data is store in the cloud and built for virtual
environment
• Object Oriented Database OO programming + Relational Database
• Graph Database node entity , edge relationship between entities
8
Amity School of Engineering & Technology
Introduction to DBMS
DBMS stands for Database Management System. We can break it like this
DBMS = Database + Management System.
Based on this we can define DBMS like this: DBMS is a collection of inter-
related data and set of programs to store & access those data in an easy and
effective manner.
Database systems are basically developed for large amount of data. When dealing
with huge amount of data, there are two things that require optimization: Storage
of data and retrieval of data.
9
Amity School of Engineering & Technology
Storage: According to the principles of database systems, the data is stored in such a
way that it acquires lot less space as the redundant data (duplicate data) has been
removed before storage.
Fast Retrieval of data: Along with storing the data in an optimized and systematic
manner, it is also important that we retrieve the data quickly when needed. Database
systems ensure that the data is retrieved as quickly as possible.
10
Amity School of Engineering & Technology
To manage this data we need to store this data somewhere where we can add new
data, delete unused data, update outdated data, retrieve data, to perform these
operations on data we need a Database management system that allows us to store
the data in such a way so that all these operations can be performed on the data
efficiently.
11
Amity School of Engineering & Technology
13
Amity School of Engineering & Technology
Disadvantages of DBMS:
DBMS implementation cost is high compared to the file system
1. Data redundancy:
2. Data Inconsistency
3. Data Isolation
4. Dependency on application programs:
5. Atomicity issues:
6. Data Security
14
Amity School of Engineering & Technology
DBMS Architecture
The architecture of DBMS depends on the computer system on which it runs.
15
Amity School of Engineering & Technology
1. In this type of architecture, the database is readily available on the client machine,
any request made by client doesn’t require a network connection to perform the
action on the database.
2. For example, lets say you want to fetch the records of employee from the database
and the database is available on your computer system, so the request to fetch
employee details will be done by your computer and the records will be fetched
from the database by your computer as well.
16
Amity School of Engineering & Technology
17
Amity School of Engineering & Technology
1. In two-tier architecture, the Database system is present at the server machine and
the DBMS application is present at the client machine, these two machines are
connected with each other through a reliable network as shown in the above
diagram.
2. Whenever client machine makes a request to access the database present at server
using a query language like sql, the server perform the request on the database and
returns the result back to the client.
3. The application connection interface such as JDBC, ODBC are used for the
interaction between server and client.
18
Amity School of Engineering & Technology
1. In three-tier architecture, another layer is present between the client machine and
server machine.
2. In this architecture, the client application doesn’t communicate directly with the
database systems present at the server machine, rather the client application
communicates with server application and the server application internally
communicates with the database system present at the server.
19
Amity School of Engineering & Technology
20
Amity School of Engineering & Technology
21
Amity School of Engineering & Technology
1. External level
2. Conceptual level
3. Internal level
1. External level
It is also called view level. The reason this level is called “view” is because several
users can view their desired data from this level which is internally fetched from
database with the help of conceptual and internal level mapping.
The user doesn’t need to know the database schema details such as data structure,
table definition etc. user is only concerned about data which is what returned back to
the view level after it has been fetched from database (present at the internal level).
External level is the “top level” of the Three Level DBMS Architecture.
22
Amity School of Engineering & Technology
2. Conceptual level
It is also called logical level. The whole design of the database such as
relationship among data, schema of data etc. are described in this level.
3. Internal level
This level is also known as physical level. This level describes how the data is
actually stored in the storage devices.
This level is also responsible for allocating space to the data. This is the lowest
level of the architecture.
23
Amity School of Engineering & Technology
The three level of DBMS architecture, The top level of that architecture is “view
level”.
The view level provides the “view of data” to the users and hides the irrelevant
details such as data relationship, database schema, constraints, security etc from the
user.
24
Amity School of Engineering & Technology
Database systems are made-up of complex data structures. To ease the user
interaction with database, the developers hide internal irrelevant details from users.
This process of hiding irrelevant details from user is called data abstraction.
1. Physical level: This is the lowest level of data abstraction. It describes how data
is actually stored in database. You can get the complex data structure details at
this level.
2. Logical level: This is the middle level of 3-level data abstraction architecture. It
describes what data is stored in database
3. View level: Highest level of data abstraction. This level describes the user
interaction with database system.
25
Amity School of Engineering & Technology
26
Amity School of Engineering & Technology
At the logical level these records can be described as fields and attributes along with
their data types, their relationship among each other can be logically implemented. The
programmers generally work at this level because they are aware of such things about
database systems.
At view level, user just interact with system with the help of GUI and enter the details at
the screen, they are not aware of how the data is stored and what data is stored; such
details are hidden from them.
27
Amity School of Engineering & Technology
For example: In the following diagram, we have a schema that shows the
relationship between three tables: Course, Student and Section.
The diagram only shows the design of the database, it doesn’t show the data
present in those tables. Schema is only a structural view(design) of a
database as shown in the diagram below.
28
Amity School of Engineering & Technology
29
Amity School of Engineering & Technology
Design of database at logical level is called logical schema, programmers and database
administrators work at this level, at this level data can be described as certain types of
data records gets stored in data structures, however the internal details such as
implementation of data structure is hidden at this level (available at physical level).
Design of database at view level is called view schema. This generally describes end
user interaction with database systems.
30
Amity School of Engineering & Technology
DBMS Instance
For example, lets say we have a single table student in the database, today the table has
100 records, so today the instance of the database has 100 records. Lets say we are
going to add another 100 records in this table by tomorrow so the instance of database
tomorrow will have 200 records in table. In short, at a particular moment the data
stored in database is called the instance, that changes over time when we add or delete
data from the database.
31
Amity School of Engineering & Technology
DBMS languages
Types of DBMS languages:
32
Amity School of Engineering & Technology
DDL is used for specifying the database schema. It is used for creating tables, schema,
indexes, constraints etc. in database. Lets see the operations that we can perform on
database using DDL:
All of these commands either defines or update the database schema that’s why they
come under Data Definition language.
33
Amity School of Engineering & Technology
1. DML is used for accessing and manipulating data in a database. The following
operations on database comes under DML:
34
Amity School of Engineering & Technology
The changes in the database that we made using DML commands are either
performed or rollbacked using TCL.
35
Amity School of Engineering & Technology
There are several types of data models in DBMS. We will cover them in detail in
separate articles(Links to those separate tutorials are already provided below). In
this guide, we will just see a basic overview of types of models.
Object based logical Models – Describe data at the conceptual and view levels.
1. E-R Model
2. Object oriented Model
36
Amity School of Engineering & Technology
37
Amity School of Engineering & Technology
38
Amity School of Engineering & Technology
39
Amity School of Engineering & Technology
40
Amity School of Engineering & Technology
41
Amity School of Engineering & Technology
42
Amity School of Engineering & Technology
43
Amity School of Engineering & Technology
44
Amity School of Engineering & Technology
45
Amity School of Engineering & Technology
46
Amity School of Engineering & Technology
47
Amity School of Engineering & Technology
48
Amity School of Engineering & Technology
49
Amity School of Engineering & Technology
50
Amity School of Engineering & Technology
51
Amity School of Engineering & Technology
52
Amity School of Engineering & Technology
53
Amity School of Engineering & Technology
54
Amity School of Engineering & Technology
55
Amity School of Engineering & Technology
56
ASET
Keys
Introduction ASET
• Keys in DBMS
• Various types of keys
• Need of keys
Need ASET
• Super Key
• Candidate Key
• Primary key
• Composite keys
Example ASET
table-1
Super key ASET
Candidate Key
• Candidate keys are defined as the minimal set of fields
which can uniquely identify each record in a table.
• It is an attribute or a set of attributes that can act as a
Primary Key for a table to uniquely identify each record
in that table.
• There can be more than one candidate key.
• In table-1, student_id and phone both are candidate
keys for table Student.
ASET
Primary Key
• Primary key is a candidate key that is most appropriate
to become the main key for any table.
• It is a key that can uniquely identify each record in a
table.
ASET
Composite Key
• Key that consists of two or more attributes that uniquely identify any
record in a table is called Composite key.
• the attributes which together form the Composite key are not a key
independentely or individually
ASET
Other keys
• Alternative key
– The candidate key which are not selected as primary key are
known as secondary keys or alternative keys.
• Non-key Attributes
– Non-key attributes are the attributes or fields of a table, other
than candidate key attributes/fields in a table.
• Non-prime Attributes
– Non-prime Attributes are attributes other than Primary Key
attribute(s)
Example ASET
table-1
Q1 ASET
table-1
Amity School of Engineering Technology
B.Tech.(CSE)
DBMS(CSE-201)
1
Learning outcomes Amity School of Engineering Technology
2
Amity School of Engineering Technology
Integrity Constraints
• Integrity constraints are used to ensure accuracy and consistency of the data in a
relational database.
• Integrity constraints are set of rules that the database is not permitted to violate.
• Constraints may apply to each attribute, or they may apply to relationship between
tables.
• Integrity constraints ensure the changes (update, deletion, insertion) made to database
by authorized users do not result in a loss of data consistency.
• Thus, integrity constraints guard against accidental damage to the database.
• Example: A blood group must be ‘A’,’B’,’AB’ or ‘O’ only.
Amity School of Engineering Technology
Amity School of Engineering Technology
Domain constraint
• Domain constraints defines the domain or the valid set of values for an attribute.
• The data type of domain includes string character, integer, time, date, currency etc. the
value of the attribute must be available in the corresponding domain.
Amity School of Engineering Technology
Entity constraint
• The entity integrity constraints states that primary key value can not be null.
• This is because the primary key value is used to identify individual rows in relation and if
the primary key has a null value, then we can not identify those rows.
• The table can contain a null value other than the primary key field.
Key constraints
• An entity set can have multiple keys or candidate keys(minimal superkey) but out of
which one key will be the primary key.
• Key constraint specifies that in any relation-
– All the values of primary key must be unique
– The value of primary key must not be null.
constraints in SQL
• DEFAULT Constraint − Provides a default value for a column when none is
specified.
• NOT NULL Constraint − Ensures that a column cannot have NULL value.
Thank You
Amity School of Engineering Technology
B.Tech.(CSE)
DBMS(CSE-201)
1
Amity School of Engineering Technology
Learning outcomes
• Students will be able to know about
– Introduction and basic
– Entity and Entity set
– Attributes and type
– Relationships
– Strong and weak entity set
2
Amity School of Engineering Technology
Introduction
• Introduced by Peter chen in 1976.
• A non-technical design method works on conceptual level
based on the perception of real world.
• Consists of collection of basic objects entities and of
relationship among these objects and attributes which define
their properties.
• Free from ambiguities and provides a standard and logical way
of visualizing data.
• Basically, it is a diagrammatic representation easy to
understand even by non technical user
Amity School of Engineering Technology
Attributes
• Are the units that describe the characteristic of entities.
Type of Attributes
Example Amity School of Engineering Technology
Amity School of Engineering Technology
Relationships
• Is an association between two and more entities of the same or
different entity set.
• No representation in E-R diagram as it is an instance or data.
• In relational model represented using a raw in the table.
Relationship Set/Type: A set of similar type of relationship.
• In a E-R diagram represented using diamond
• In relational model either by a separate table or by separate
Column (F.Key)
• Every relationship type has 3 components
– Name , Degree, Cordiality /participation
Amity School of Engineering Technology
Participation
• Specifies weather the existence of an entity depends on its being related
to another entity via a relationship type.
• These constraints specify the minimum and maximum no of relationship
instances that each entity can/must participates.
• Max Cardinality: it defines the max no of times an entity occurrence
participating in a relationship.
• Min. Cardinality: it define the min no of times an entity occurrence
participating in a relationship
• Partial participation
• Total participation
• Weak Entity
Amity School of Engineering Technology
Steps in ER Modeling
• Identify the Entities
• Find relationships
• Identify the key attributes for every Entity
• Identify other relevant attributes
• Draw complete E-R diagram with all attributes including Primary Key
• Review your results with your Business users
Amity School of Engineering Technology
• Some Customers also had taken different types of loans from these bank
branches
Extended ER Model
Amity School of Engineering Technology
Generalization
Amity School of Engineering Technology
Example: Generalization
Amity School of Engineering Technology
Specialization
Amity School of Engineering Technology
Example: Specialization
Amity School of Engineering Technology
Inheritance
Amity School of Engineering Technology
Amity School of Engineering Technology
Amity School of Engineering Technology
Aggregation
Amity School of Engineering Technology
Aggregation
Amity School of Engineering Technology
Example Aggregation
Amity School of Engineering Technology
Thank You
Amity School of Engineering & Technology
1
Amity School of Engineering & Technology
Course Objectives:
1. The objective of this course is to get students familiar with Databases and
their use.
2. Case studies
3. Lab work
2
Amity School of Engineering & Technology
1. Understand the database fundamentals along with conceptual modeling to deal real
life applications.
2. Develop the ability to retrieve and manipulate information for business decision
making from databases
4. Understand the query processing techniques to automate the real time problems of
databases.
3
Amity School of Engineering & Technology
4
Amity School of Engineering & Technology
This model is simple and it has all the properties and capabilities
required to process data with storage efficiency..
5
Amity School of Engineering & Technology
6
Amity School of Engineering & Technology
8
Amity School of Engineering & Technology
The changes in the database that we made using DML commands are either
performed or rollbacked using TCL.
9
Amity School of Engineering & Technology
Key Constraints
An attribute that can uniquely identify a tuple in a relation is called the key of the
table. The value of the attribute for different tuples in the relation has to be unique.
Example:
In the given table, CustomerID is a key attribute of Customer Table. It is most likely
to have a single key for one customer, CustomerID =1 is only for the CustomerName
=" Google".
10
Student(Enrollnment, Name, DOB, Address, Batch, Age, Coursename,
Hostel, gender, ContactNo, Year_of_Passing, Grades, Email-id, Date_of
Attendance)
11
Amity School of Engineering & Technology
12
Amity School of Engineering & Technology
Whenever one of these operations are applied, integrity constraints specified on the
relational database schema must never be violated.
14
Amity School of Engineering & Technology
Insert Operation
The insert operation gives values of the attribute for a new tuple which should be
inserted into a relation.
15
Amity School of Engineering & Technology
Update Operation
You can see that in the below-given relation table CustomerName= 'Apple' is updated
from Inactive to Active.
16
Amity School of Engineering & Technology
Select Operation
17
Amity School of Engineering & Technology
Delete Operation
To specify deletion, a condition on the attributes of the relation selects the tuple to be
deleted.
19
Amity School of Engineering & Technology
RELATIONAL ALGEBRA
It is a widely used procedural query language. It collects instances of relations as input and gives
occurrences of relations as output. It uses various operations to perform this action. SQL
Relational algebra query operations are performed recursively on a relation. The output of these
operations is a new relation, which might be formed from one or more input relations.
21
22
Amity School of Engineering & Technology
23
Amity School of Engineering & Technology
24
Amity School of Engineering & Technology
25
Amity School of Engineering & Technology
1. SELECT (σ)
The select operation selects tuples that satisfy a given predicate.
It is denoted by sigma (σ).
Notation: σ p(r)
Where:
σ is used for selection prediction
r is used for relation
p is used as a propositional logic formula which may use connectors like: AND OR and
NOT. These relational can use as relational operators like =, ≠, ≥, <, >, ≤.
For example: LOAN Relation
Example 2
σ topic = "Database" and author = “Korth"( Tutorials)
Output – Selects tuples from Tutorials where the topic is ‘Database’ and ‘author’ is Korth.
Example 3
σ sales > 50000 (Customers)
Output – Selects tuples from Customers (tablename) where sales is greater than 50000
27
Amity School of Engineering & Technology
Input:
28
29
Amity School of Engineering & Technology
2. Project Operation:
This operation shows the list of those attributes that we wish to appear in the result. Rest of
the attributes are eliminated from the table.
It is denoted by ∏.
Notation: ∏ A1, A2, An (r)
Where
A1, A2, A3 is used as an attribute name of relation r.
Example: CUSTOMER RELATION
Input:
∏ NAME, CITY (CUSTOMER)
Output
NAME CITY
Jones Harrison
Smith Rye
Hays Harrison
Curry Rye
Johnson Brooklyn
Brooks Brooklyn
31
32
BRANCH_NAME LOAN_NO AMOUNT
33
Amity School of Engineering & Technology
3. Union Operation:
Suppose there are two tuples R and S. The union operation contains all the tuples that are
either in R or S or both in R & S.
It eliminates the duplicate tuples. It is denoted by ∪.
Notation: R ∪ S
A union operation must hold the following condition:
R and S must have the attribute of the same number.
Duplicate tuples are eliminated automatically.
Example: DEPOSITOR RELATION
CUSTOMER_NAME ACCOUNT_NO
Johnson A-101
Smith A-121
Mayes A-321
Turner A-176
Johnson A-273
Jones A-472
Lindsay A-284
34
Amity School of Engineering & Technology
BORROW RELATION
CUSTOMER_NAME LOAN_NO
Jones L-17
Smith L-23
Hayes L-15
Jackson L-14
Curry L-93
Smith L-11
Williams L-17
Input:
∏ CUSTOMER_NAME (BORROW) ∪ ∏ CUSTOMER_NAME (DEPOSITOR)
35
Amity School of Engineering & Technology
Output
CUSTOMER_NAME
Johnson
Smith
Hayes
Turner
Jones
Lindsay
Jackson
Curry
Williams
Mayes
36
Amity School of Engineering & Technology
5. Set Difference:
Suppose there are two tuples R and S. The set intersection operation contains all
tuples that are in R but not in S.
It is denoted by intersection minus (-).
Notation: R - S
Jackson
Hayes
Willians
Curry
37
Amity School of Engineering & Technology
4. Set Intersection:
Suppose there are two tuples R and S. The set intersection operation contains all
tuples that are in both R & S.
It is denoted by intersection ∩.
Notation: R ∩ S
CUSTOMER_NAME
Smith
Jones
38
Amity School of Engineering & Technology
6. Cartesian product
The Cartesian product is used to combine each row in one table with each row in
the other table. It is also known as a cross product.
It is denoted by X.
Notation: E X D
Example: EMPLOYEE
EMP_ID EMP_NAME EMP_DEPT
1 Smith A
2 Harry C
3 John B
DEPARTMENT
DEPT_NO DEPT_NAME
A Marketing
B Sales
C Legal
39
Amity School of Engineering & Technology
1 Smith A A Marketing
1 Smith A B Sales
1 Smith A C Legal
2 Harry C A Marketing
2 Harry C B Sales
2 Harry C C Legal
3 John B A Marketing
3 John B B Sales
3 John B C Legal
40
Amity School of Engineering & Technology
Examples of queries
41
Amity School of Engineering & Technology
Examples of queries
42
Amity School of Engineering & Technology
Examples of queries
43
Amity School of Engineering & Technology
44
Amity School of Engineering & Technology
Additional Operators
45
Amity School of Engineering & Technology
7. Rename Operation:
The rename operation is used to rename the output relation. It is denoted by rho (ρ).
ρ(STUDENT1, STUDENT)
46
Amity School of Engineering & Technology
Join Operations: A Join operation combines related tuples from different relations, if
and only if a given join condition is satisfied. It is denoted by ⋈.
Example: EMPLOYEE
EMP_CODE EMP_NAME
101 Stephan
102 Jack
103 Harry
SALARY
EMP_CODE SALARY
101 50000
102 30000
103 25000
47
Amity School of Engineering & Technology
48
Amity School of Engineering & Technology
SQL-
1. Equi
2. Non-Equi
3. Self join
4. Outer Join
(+)
5. Between
49
Amity School of Engineering & Technology
1. Natural Join:
A natural join is the set of tuples of all combinations in R and S that are equal on
their common attribute names.
It is denoted by ⋈.
Example: Let's use the above EMPLOYEE table and SALARY table:
Input:
∏EMP_NAME, SALARY (EMPLOYEE ⋈ SALARY)
(Select emp_name, salary from employee e, salary s where e.emp_code=s.emp_code; )
Output:
EMP_NAME SALARY
Stephan 50000
Jack 30000
Harry 25000
50
Amity School of Engineering & Technology
2. Outer Join:
The outer join operation is an extension of the join operation. It is used to deal with
missing information.
Example: EMPLOYEE
EMP_NAME STREET CITY
FACT_WORKERS
EMP_NAME BRANCH SALARY
51
Amity School of Engineering & Technology
Input:
(EMPLOYEE ⋈ FACT_WORKERS)
Output:
52
Amity School of Engineering & Technology
53
Amity School of Engineering & Technology
54
Amity School of Engineering & Technology
55
Amity School of Engineering & Technology
3. Equi join:
It is also known as an inner join. It is the most common join. It is based on matched
data as per the equality condition. The equi join uses the comparison operator(=).
Example: CUSTOMER RELATION
CLASS_ID NAME
1 John
2 Harry
3 Jackson
PRODUCT
PRODUCT_ID CITY
1 Delhi
2 Mumbai
3 Noida
56
Amity School of Engineering & Technology
1 John 1 Delhi
2 Harry 2 Mumbai
3 Jackson 3 Noida
57
Amity School of Engineering & Technology
Surprise-Class Test
58
Amity School of Engineering & Technology
Surprise-Class Test
59
Amity School of Engineering & Technology
60
Amity School of Engineering & Technology
61
Amity School of Engineering & Technology
62
Amity School of Engineering & Technology
63
Amity School of Engineering & Technology
64
Amity School of Engineering & Technology
65
Amity School of Engineering & Technology
Note that Member relation has 5 tuples and Burrow relation has 5 tuples.
Hence Member ✕ Borrow has 5✕5 = 25 tuples.
66
Amity School of Engineering & Technology
67
Amity School of Engineering & Technology
68
Amity School of Engineering & Technology
69
Amity School of Engineering & Technology
70
Amity School of Engineering & Technology
R1 will return details of all the members Alice, Bob, Charlie, Mike and Katie.
R2 will return details of Alice, Charlie, Mike and Katie as they have borrowed
books. When we take the difference between R1 and R2, the details of Bob
will be returned.
71
Amity School of Engineering & Technology
References
https://towardsdatascience.com/a-quick-guide-to-relational-algebra-
operators-in-dbms-1ff2ddeca
https://slideplayer.com/slide/4814012/
chrome-
extension://ohfgljdgelakfkefopgklcohadegdpjf/https://cdn.prexams.com/62
86/Chapter4Ex.pdf
https://www.coursehero.com/file/p45ur8b/78-Q15-Find-the-sids-of-
suppliers-who-supply-every-part-Solution-1-%CF%80-sidpid/
72
Amity School of Engineering & Technology
Relational Calculus
73
Amity School of Engineering & Technology
Tuple relational calculus which was originally proposed by Codd in the year
1972 and
Domain relational calculus which was proposed by Lacroix and Pirotte in the
year 1977
2. For example, steps involved in listing all the employees who attend the 'Networking'
Course would be:
SELECT the tuples from COURSE relation with COURSENAME =
'NETWORKING‘
PROJECT the COURSE_ID from above result 74
SELECT the tuples from EMP relation with COURSE_ID resulted above.
Amity School of Engineering & Technology
P(t) = known as Predicate and these are the conditions that are used to
fetch t
Thus, it generates set of all tuples t, such that Predicate P(t) is true for
t.
P(t) may have various conditions logically combined with OR (∨), AND
(∧), NOT(¬).
t r denotes that tuple t is in relation r
P is a formula similar to that of the predicate calculus 75
Amity School of Engineering & Technology
76
Existential quantifier is represented by the symbol ∃ and the
syntax of the query with the existential quantifier can be represented
as:
∃T ε Cond (T)
The query will succeed only if the condition turns to be true for at
least some tuples in T.
∀ T ε Cond (T)
The query will succeed only if the condition comes out to be true for
all the tuples in T.
77
Amity School of Engineering & Technology
Staff(S)
2. To express the query 'Find the set of all tuples S such that F(S) is true,' we can write:
{S | F(S)}
3. For example, to express the query 'Find the staffNo, fName, lName, position, DOB,
salary, and branchNo of all staff earning more than £10,000', we can write:
It implies that it selects the tuples from the TEACHER in such a way that the
resulting teacher tuples will have a salary higher than 20000. This is an example
of selecting a range of values.
T select all the tuples of teachers' names who work under Department 8. Any
tuple variable with 'For All' (?) or 'there exists' (?) condition is termed as a bound
variable.
In the last example, for any range of values of SALARY greater than 20000, the
meaning of the condition does not alter. Bound variables are those ranges of tuple
variables whose meaning will not alter if another tuple variable replaces the tuple
variable.
In the second example, you have used DEPT_ID= 8, which means only for
DEPT_ID = 8 display the teacher details. Such a variable is called a free variable.
Any tuple variable without any 'For All' or 'there exists' condition is called Free
Variable.
79
Examples
1. Find the last names and hire dates of employees who make more than $100000.
2. Retrieve details of all films that were released in 2010. The output schema should be
the same as that of the Film table.
3. Retrieve details of all actors that are not in their thirties. The output schema should
be the same as that of the Film table.
6. Find out the names of all British actors above the age of 40.
{ T | ∃A ∈ Actor (A.nationality = ’British’ ∧ A.age > 40 ∧ T.name = A.name) }
πname(σ(nationality=’British’∧age>40)(Actor))
7. Retrieve the name of each actor together with the titles of the films he/she
has performed in.
{ T | ∃A ∈ Actor, P ∈ Performance, F ∈ Film (A.actorId = P.actorId ∧ P.filmId =
F.filmId ∧ T.name = A.name ∧ T. title = F. title) }
πname, title (Actor (Performance ./ Film))
81
8. Find out the names of all actors that have played the character of Bruce Wayne
(Batman; see also Marshall et al., Physics Special Topics 10(1):2011).
9. Retrieve the names of all actors that have played the character of Bruce Wayne,
together with the year the corresponding films were released.
10. Retrieve all actors that appeared in Inception. The output schema should be the
same as that of the Actor table.
12. Retrieve the titles of all films in which Leonardo Di Caprio and Kate Winslet have co-
acted.
13. Assuming that the actorId and directorId values for actors and directors are
consistent across the tables, retrieve details of all actors that have directed a film.
Example Queries
Find the ID, name, dept_name, salary for instructors
whose salary is greater than $80,000
84
Amity School of Engineering & Technology
Example Queries
Find the set of all courses taught in the Fall 2009 semester, or in
the Spring 2010 semester, or both
{t | s section (t [course_id ] = s [course_id ] s [semester] = “Fall” s [year]
= 2009 v u section (t [course_id ] = u [course_id ] u [semester] =
“Spring” u [year] = 2010 )}
85
Amity School of Engineering & Technology
Example Queries
Find the set of all courses taught in the Fall 2009 semester, and in
the Spring 2010 semester
{t | s section (t [course_id ] = s [course_id ]
s [semester] = “Fall” s [year] = 2009
u section (t [course_id ] = u [course_id ]
u [semester] = “Spring” u [year] = 2010 )}
Find the set of all courses taught in the Fall 2009 semester, but not in
the Spring 2010 semester
90
Solution
91
Example Queries 2
92
Example Queries 3
93
Amity School of Engineering & Technology
Example Queries 4
• Find the ID, name, dept_name, salary for instructors whose salary is
greater than $80,000
– {< i, n, d, s> | < i, n, d, s> instructor s 80000}
• As in the previous query, but output only the ID attribute value
– {< i> | < i, n, d, s> instructor s 80000}
• Find the names of all instructors whose department is in the Watson
building
{< n > | i, d, s (< i, n, d, s > instructor
b, a (< d, b, a> department b = “Watson” ))}
Amity School of Engineering & Technology
Find the set of all courses taught in the Fall 2009 semester, or in
the Spring 2010 semester, or both
{<c> | a, s, y, b, r, t ( <c, a, s, y, b, r, t > section
s = “Fall” y = 2009 )
v a, s, y, b, r, t ( <c, a, s, y, b, r, t > section ]
s = “Spring” y = 2010)}
This case can also be written as
{<c> | a, s, y, b, r, t ( <c, a, s, y, b, r, t > section
( (s = “Fall” y = 2009 ) v (s = “Spring” y = 2010))}
Find the set of all courses taught in the Fall 2009 semester, and in
the Spring 2010 semester
96
Thanks
97