SlideShare a Scribd company logo
1 of 76
Database System Concepts, 6th Ed.
©Silberschatz, Korth and Sudarshan
See www.db-book.com for conditions on re-use
Chapter 6: Formal Relational Query Languages
©Silberschatz, Korth and Sudarshan
6.*
Database System Concepts - 6th Edition
Chapter 6: Formal Relational Query LanguagesRelational
AlgebraTuple Relational CalculusDomain Relational Calculus
©Silberschatz, Korth and Sudarshan
6.*
Database System Concepts - 6th Edition
Relational AlgebraProcedural languageSix basic
operators – Cartesian
inputs and produce a new relation as a result.
©Silberschatz, Korth and Sudarshan
6.*
Database System Concepts - 6th Edition
Select Operation –
©Silberschatz, Korth and Sudarshan
6.*
Database System Concepts - 6th Edition
predicateDefined as:
Where p is a formula in propositional calculus consisting
Each term is one of:
<attribute> op <attribute> or <constant>
Example of selection:
structor)
©Silberschatz, Korth and Sudarshan
6.*
Database System Concepts - 6th Edition
Project Operation – ExampleRelation r:
©Silberschatz, Korth and Sudarshan
6.*
Database System Concepts - 6th Edition
Project OperationNotation:
where A1, A2 are attribute names and r is a relation
name.The result is defined as the relation of k columns obtained
by erasing the columns that are not listedDuplicate rows
removed from result, since relations are setsExample: To
eliminate the dept_name attribute of instructor
©Silberschatz, Korth and Sudarshan
6.*
Database System Concepts - 6th Edition
Union Operation –
©Silberschatz, Korth and Sudarshan
6.*
Database System Concepts - 6th Edition
1. r, s must have the same arity (same number of
attributes)
2. The attribute domains must be compatible (example:
2nd column
of r deals with the same type of values as does the 2nd
column of s)Example: to find all courses taught in the Fall
2009 semester, or in the Spring 2010 semester, or in both
©Silberschatz, Korth and Sudarshan
6.*
Database System Concepts - 6th Edition
Set difference of two relationsRelations r, s:r – s:
©Silberschatz, Korth and Sudarshan
6.*
Database System Concepts - 6th Edition
Set Difference OperationNotation r – sDefined as:
r –
Set differences must be taken between compatible relations.r
and s must have the same arityattribute domains of r and s must
be compatibleExample: to find all courses taught in the Fall
2009 semester, but not in the Spring 2010 semester
©Silberschatz, Korth and Sudarshan
6.*
Database System Concepts - 6th Edition
Cartesian-Product Operation – ExampleRelations r, s:r x s:
©Silberschatz, Korth and Sudarshan
6.*
Database System Concepts - 6th Edition
Cartesian-Product OperationNotation r x sDefined as:
r x s = {t
Assume that attributes of r(R) and s(S) are disjoint. (That is, R
renaming must be used.
©Silberschatz, Korth and Sudarshan
6.*
Database System Concepts - 6th Edition
Composition of OperationsCan build expressions using multiple
r x s
©Silberschatz, Korth and Sudarshan
6.*
Database System Concepts - 6th Edition
Rename OperationAllows us to name, and therefore to refer to,
the results of relational-algebra expressions.Allows us to refer
to a relation by more than one name.Example:
returns the expression E under the name XIf a relational-
algebra expression E has arity n, then
returns the result of expression E under the name X, and
with the
attributes renamed to A1 , A2 , …., An .
©Silberschatz, Korth and Sudarshan
6.*
Database System Concepts - 6th Edition
Example QueryFind the largest salary in the universityStep 1:
find instructor salaries that are less than some other instructor
salary (i.e. not maximum)
Find t –
©Silberschatz, Korth and Sudarshan
6.*
Database System Concepts - 6th Edition
Example QueriesFind the names of all instructors in the Physics
department, along with the course_id of all courses they have
taughtQuery 1
teaches)))Query 2
©Silberschatz, Korth and Sudarshan
6.*
Database System Concepts - 6th Edition
Formal DefinitionA basic expression in the relational algebra
consists of either one of the following:A relation in the
databaseA constant relationLet E1 and E2 be relational-algebra
expressions; the following are all relational-algebra
– ate
©Silberschatz, Korth and Sudarshan
6.*
Database System Concepts - 6th Edition
Additional Operations
We define additional operations that do not add any power to
the
relational algebra, but that simplify common queries.Set
intersectionNatural joinAssignmentOuter join
©Silberschatz, Korth and Sudarshan
6.*
Database System Concepts - 6th Edition
Set-Intersection Ope
– (r – s)
©Silberschatz, Korth and Sudarshan
6.*
Database System Concepts - 6th Edition
Set-Intersection Operation – ExampleRelation r, s:
©Silberschatz, Korth and Sudarshan
6.*
Database System Concepts - 6th Edition
Natural-Join OperationLet r and s be relations on schemas R and
S respectively.
Then, r s is a relation on schema R
follows:Consider each pair of tuples tr from r and ts from s. If
add a tuple t to the result, wheret has the same value as tr on rt
has the same value as ts on sExample:
R = (A, B, C, D)
S = (E, B, D)Result schema = (A, B, C, D, E)r s is defined
as:
Notation: r s
©Silberschatz, Korth and Sudarshan
6.*
Database System Concepts - 6th Edition
Natural Join ExampleRelations r, s:r s
©Silberschatz, Korth and Sudarshan
6.*
Database System Concepts - 6th Edition
Natural Join and Theta JoinFind the names of all instructors in
the Comp. Sci. department together with the course titles of all
dept_name=“Comp. Sci.” (instructor teaches
course))Natural join is associative(instructor teaches)
course is equivalent to
instructor (teaches course)Natural join is
commutativeinstruct teaches is equivalent to
©Silberschatz, Korth and Sudarshan
6.*
Database System Concepts - 6th Edition
Assignment Operati
convenient way to express complex queries. Write query as a
sequential program consisting ofa series of assignments
followed by an expression whose value is displayed as a result
of the query.Assignment must always be made to a temporary
relation variable.
©Silberschatz, Korth and Sudarshan
6.*
Database System Concepts - 6th Edition
Outer JoinAn extension of the join operation that avoids loss of
information.Computes the join and then adds tuples form one
relation that does not match tuples in the other relation to the
result of the join. Uses null values:null signifies that the value
is unknown or does not exist All comparisons involving null are
(roughly speaking) false by definition.We shall study precise
meaning of comparisons with nulls later
©Silberschatz, Korth and Sudarshan
6.*
Database System Concepts - 6th Edition
Outer Join – ExampleRelation instructor1Relation teaches1
ID
course_id
10101
12121
76766
CS-101
FIN-201
BIO-101
Comp. Sci.
Finance
Music
ID
dept_name
10101
12121
15151
name
Srinivasan
Wu
Mozart
©Silberschatz, Korth and Sudarshan
6.*
Database System Concepts - 6th Edition
Outer Join – ExampleJoin
instructor teaches Left Outer Join
instructor teaches
ID
dept_name
10101
12121
Comp. Sci.
Finance
course_id
CS-101
FIN-201
name
Srinivasan
Wu
ID
dept_name
10101
12121
15151
Comp. Sci.
Finance
Music
course_id
CS-101
FIN-201
null
name
Srinivasan
Wu
Mozart
©Silberschatz, Korth and Sudarshan
6.*
Database System Concepts - 6th Edition
Outer Join – Example
Full Outer Join
instructor teaches Right Outer Join
instructor teaches
ID
dept_name
10101
12121
76766
Comp. Sci.
Finance
null
course_id
CS-101
FIN-201
BIO-101
name
Srinivasan
Wu
null
ID
dept_name
10101
12121
15151
76766
Comp. Sci.
Finance
Music
null
course_id
CS-101
FIN-201
null
BIO-101
name
Srinivasan
Wu
Mozart
null
©Silberschatz, Korth and Sudarshan
6.*
Database System Concepts - 6th Edition
Outer Join using JoinsOuter join can be expressed using basic
operationse.g. r s can be written as
(r s) U (r – ∏R(r s) x {(null, …, null)}
©Silberschatz, Korth and Sudarshan
6.*
Database System Concepts - 6th Edition
Null ValuesIt is possible for tuples to have a null value, denoted
by null, for some of their attributesnull signifies an unknown
value or that a value does not exist.The result of any arithmetic
expression involving null is null.Aggregate functions simply
ignore null values (as in SQL)For duplicate elimination and
grouping, null is treated like any other value, and two nulls are
assumed to be the same (as in SQL)
©Silberschatz, Korth and Sudarshan
6.*
Database System Concepts - 6th Edition
Null ValuesComparisons with null values return the special
truth value: unknownIf false was used instead of unknown, then
not (A < 5)
would not be equivalent to A >= 5Three-
valued logic using the truth value unknown:OR: (unknown or
true) = true,
(unknown or false) = unknown
(unknown or unknown) = unknownAND: (true and
unknown) = unknown,
(false and unknown) = false,
(unknown and unknown) = unknownNOT: (not
unknown) = unknownIn SQL “P is unknown” evaluates to true if
predicate P evaluates to unknownResult of select predicate is
treated as false if it evaluates to unknown
©Silberschatz, Korth and Sudarshan
6.*
Database System Concepts - 6th Edition
Division OperatorGiven
-S) such that
(takes ) and
then r
-S (r )
-S ((temp1 x s ) – -S,S (r ))
result = temp1 –
is assigned to the relation variable
variable in subsequent expressions.
©Silberschatz, Korth and Sudarshan
6.*
Database System Concepts - 6th Edition
Extended Relational-Algebra-OperationsGeneralized
ProjectionAggregate Functions
©Silberschatz, Korth and Sudarshan
6.*
Database System Concepts - 6th Edition
Generalized ProjectionExtends the projection operation by
allowing arithmetic functions to be used in the projection list.
E is any relational-algebra expressionEach of F1, F2, …, Fn are
are arithmetic expressions involving constants and attributes in
the schema of E.Given relation instructor(ID, name, dept_name,
salary) where salary is annual salary, get the same information
but with monthly salary
©Silberschatz, Korth and Sudarshan
6.*
Database System Concepts - 6th Edition
Aggregate Functions and OperationsAggregation function takes
a collection of values and returns a single value as a result.
avg: average value
min: minimum value
max: maximum value
sum: sum of values
count: number of valuesAggregate operation in relational
algebra
E is any relational-algebra expressionG1, G2 …, Gn is a list of
attributes on which to group (can be empty)Each Fi is an
aggregate functionEach Ai is an attribute nameNote: Some
©Silberschatz, Korth and Sudarshan
6.*
Database System Concepts - 6th Edition
Aggregate Operation – ExampleRelation r:
A
B
C
7
7
3
10 sum(c) (r)
sum(c )
27
©Silberschatz, Korth and Sudarshan
6.*
Database System Concepts - 6th Edition
Aggregate Operation – ExampleFind the average salary in each
department
dept_name avg(salary) (instructor)
avg_salary
©Silberschatz, Korth and Sudarshan
6.*
Database System Concepts - 6th Edition
Aggregate Functions (Cont.)Result of aggregation does not have
a nameCan use rename operation to give it a nameFor
convenience, we permit renaming as part of aggregate operation
dept_name avg(salary) as avg_sal (instructor)
©Silberschatz, Korth and Sudarshan
6.*
Database System Concepts - 6th Edition
Modification of the DatabaseThe content of the database may be
modified using the following
operations:DeletionInsertionUpdatingAll these operations can
be expressed using the assignment operator
©Silberschatz, Korth and Sudarshan
6.*
Database System Concepts - 6th Edition
Multiset Relational AlgebraPure relational algebra removes all
duplicates e.g. after projectionMultiset relational algebra retains
duplicates, to match SQL semanticsSQL duplicate retention was
initially for efficiency, but is now a featureMultiset relational
algebra defined as followsselection: has as many duplicates of a
tuple as in the input, if the tuple satisfies the
selectionprojection: one tuple per input tuple, even if it is a
duplicatecross product: If there are m copies of t1 in r, and n
copies of t2 in s, there are m x n copies of t1.t2 in r x sOther
operators similarly defined E.g. union: m + n copies,
intersection: min(m, n) copies
difference: min(0, m – n) copies
©Silberschatz, Korth and Sudarshan
6.*
Database System Concepts - 6th Edition
SQL and Relational Algebraselect A1, A2, .. An
from r1, r2, …, rm
where P
is equivalent to the following expression in multiset
relational algebra
sum(A3)
from r1, r2, …, rm
where P
group by A1, A2
is equivalent to the following expression in multiset
relational algebra
©Silberschatz, Korth and Sudarshan
6.*
Database System Concepts - 6th Edition
SQL and Relational AlgebraMore generally, the non-aggregated
attributes in the select clause may be a subset of the group by
attributes, in which case the equivalence is as follows:
select A1, sum(A3)
from r1, r2, …, rm
where P
group by A1, A2
is equivalent to the following expression in multiset
relational algebra
(r1 x r2 x
.. x rm)))
©Silberschatz, Korth and Sudarshan
6.*
Database System Concepts - 6th Edition
Tuple Relational Calculus
©Silberschatz, Korth and Sudarshan
6.*
Database System Concepts - 6th Edition
Tuple Relational CalculusA nonprocedural query language,
where each query is of the form
{t | P (t ) }It is the set of all tuples t such that
predicate P is true for tt is a tuple variable, t [A ] denotes the
relation rP is a formula similar to that of the predicate calculus
©Silberschatz, Korth and Sudarshan
6.*
Database System Concepts - 6th Edition
Predicate Calculus Formula
1. Set of attributes and constants
2.
3. Se
4.
5. Set of quantifiers:
such that predicate Q (t ) is true
©Silberschatz, Korth and Sudarshan
6.*
Database System Concepts - 6th Edition
Example QueriesFind the ID, name, dept_name, salary for
instructors whose salary is greater than $80,000 As in the
previous query, but output only the ID attribute value
80000)}
Notice that a relation on schema (ID) is implicitly defined
by
the query
©Silberschatz, Korth and Sudarshan
6.*
Database System Concepts - 6th Edition
Example QueriesFind the names of all instructors whose
department is in the Watson building
Find the set of all courses taught in the Fall 2009 semester, or
in
the Spring 2010 semester, or both
©Silberschatz, Korth and Sudarshan
6.*
Database System Concepts - 6th Edition
Example Queries
Find the set of all courses taught in the Fall 2009 semester, and
in
the Spring 2010 semester
s [semester] = “Fal
Find the set of all courses taught in the Fall 2009 semester, but
not in
the Spring 2010 semester
©Silberschatz, Korth and Sudarshan
6.*
Database System Concepts - 6th Edition
Safety of ExpressionsIt is possible to write tuple calculus
domain of any
attribute of relation r is infiniteTo guard against the problem,
we restrict the set of allowable expressions to safe
expressions.An expression {t | P (t )} in the tuple relational
calculus is safe if every component of t appears in one of the
relations, tuples, or constants that appear in PNOTE: this is
not safe --- it defines an infinite set with attribute values that do
not appear in any relation or tuples or constants in P.
©Silberschatz, Korth and Sudarshan
6.*
Database System Concepts - 6th Edition
Universal QuantificationFind all students who have taken all
s [course_id] = u [course_id]))}Note that
without the existential quantification on student, the above
query would be unsafe if the Biology department has not offered
any courses.
©Silberschatz, Korth and Sudarshan
6.*
Database System Concepts - 6th Edition
Domain Relational Calculus
©Silberschatz, Korth and Sudarshan
6.*
Database System Concepts - 6th Edition
Domain Relational CalculusA nonprocedural query language
equivalent in power to the tuple relational calculusEach query is
an expression of the form:
x1, x2, …, xn represent domain variablesP represents a formula
similar to that of the predicate calculus
©Silberschatz, Korth and Sudarshan
6.*
Database System Concepts - 6th Edition
Example QueriesFind the ID, name, dept_name, salary for
instructors whose salary is greater than $80,000{< i, n, d, s> | <
department is in the Watson building
instructor
))}
©Silberschatz, Korth and Sudarshan
6.*
Database System Concepts - 6th Edition
Example Queries
courses taught in the Fall 2009 semester, or in
the Spring 2010 semester, or both
This case can also be written as
2010))} Find the set of all courses taught in the Fall 2009
semester, and in
the Spring 2010 semester
©Silberschatz, Korth and Sudarshan
6.*
Database System Concepts - 6th Edition
Safety of Expressions
The expression:
is safe if all of the following hold:
All values that appear in tuples of the expression are values
from dom (P ) (that is, the values appear either in P or in a
tuple of a relation mentioned in P ).
the subformula is true if and only if there is a value of x in
dom (P1) such that P1(x ) is true.
subformula is true if and only if P1(x ) is true for all values x
from dom (P1).
©Silberschatz, Korth and Sudarshan
6.*
Database System Concepts - 6th Edition
Universal QuantificationFind all students who have taken all
=“Biology”
))}Note that without the existential quantification on student,
the above query would be unsafe if the Biology department has
not offered any courses.
* Above query fixes bug in page 246, last query
Database System Concepts, 6th Ed.
©Silberschatz, Korth and Sudarshan
See www.db-book.com for conditions on re-use
End of Chapter 6
©Silberschatz, Korth and Sudarshan
6.*
Database System Concepts - 6th Edition
Figure 6.01
©Silberschatz, Korth and Sudarshan
6.*
Database System Concepts - 6th Edition
Figure 6.02
©Silberschatz, Korth and Sudarshan
6.*
Database System Concepts - 6th Edition
Figure 6.03
©Silberschatz, Korth and Sudarshan
6.*
Database System Concepts - 6th Edition
Figure 6.04
©Silberschatz, Korth and Sudarshan
6.*
Database System Concepts - 6th Edition
Figure 6.05
©Silberschatz, Korth and Sudarshan
6.*
Database System Concepts - 6th Edition
Figure 6.06
©Silberschatz, Korth and Sudarshan
6.*
Database System Concepts - 6th Edition
Figure 6.07
©Silberschatz, Korth and Sudarshan
6.*
Database System Concepts - 6th Edition
Figure 6.08
©Silberschatz, Korth and Sudarshan
6.*
Database System Concepts - 6th Edition
Figure 6.09
©Silberschatz, Korth and Sudarshan
6.*
Database System Concepts - 6th Edition
Figure 6.10
©Silberschatz, Korth and Sudarshan
6.*
Database System Concepts - 6th Edition
Figure 6.11
©Silberschatz, Korth and Sudarshan
6.*
Database System Concepts - 6th Edition
Figure 6.12
©Silberschatz, Korth and Sudarshan
6.*
Database System Concepts - 6th Edition
Figure 6.13
©Silberschatz, Korth and Sudarshan
6.*
Database System Concepts - 6th Edition
Figure 6.14
©Silberschatz, Korth and Sudarshan
6.*
Database System Concepts - 6th Edition
Figure 6.15
©Silberschatz, Korth and Sudarshan
6.*
Database System Concepts - 6th Edition
Figure 6.16
©Silberschatz, Korth and Sudarshan
6.*
Database System Concepts - 6th Edition
Figure 6.17
©Silberschatz, Korth and Sudarshan
6.*
Database System Concepts - 6th Edition
Figure 6.18
©Silberschatz, Korth and Sudarshan
6.*
Database System Concepts - 6th Edition
Figure 6.19
©Silberschatz, Korth and Sudarshan
6.*
Database System Concepts - 6th Edition
Figure 6.20
©Silberschatz, Korth and Sudarshan
6.*
Database System Concepts - 6th Edition
Figure 6.21
©Silberschatz, Korth and Sudarshan
6.*
Database System Concepts - 6th Edition
DeletionA delete request is expressed similarly to a query,
except instead of displaying tuples to the user, the selected
tuples are removed from the database.Can delete only whole
tuples; cannot delete values on only particular attributesA
deletion is expressed in relational algebra by:
– E
where r is a relation and E is a relational algebra query.
©Silberschatz, Korth and Sudarshan
6.*
Database System Concepts - 6th Edition
Deletion ExamplesDelete all account records in the Perryridge
branch. Delete all accounts at branches located in Needham.
Delete all loan records with amount in the range of 0 to 50
–
–
branch )
– r2
– r3
©Silberschatz, Korth and Sudarshan
6.*
Database System Concepts - 6th Edition
InsertionTo insert data into a relation, we either:specify a tuple
to be insertedwrite a query whose result is a set of tuples to be
insertedin relational algebra, an insertion is expressed by:
where r is a relation and E is a relational algebra
expression.The insertion of a single tuple is expressed by letting
E be a constant relation containing one tuple.
©Silberschatz, Korth and Sudarshan
6.*
Database System Concepts - 6th Edition
Insertion ExamplesInsert information in the database specifying
that Smith has $1200 in account A-973 at the Perryridge branch.
Provide as a gift for all loan customers in the Perryridge
branch, a $200 savings account. Let the loan number serve
as the account number for the new savings account.
acc -973”, “Perryridge”, 1200)}
-973”)}
number (r1)
©Silberschatz, Korth and Sudarshan
6.*
Database System Concepts - 6th Edition
UpdatingA mechanism to change a value in a tuple without
charging all values in the tupleUse the generalized projection
operator to do this task
Each Fi is either the I th attribute of r, if the I th attribute is not
updated, or,if the attribute is to be updated Fi is an expression,
involving only constants and the attributes of r, which gives the
new value for the attribute
©Silberschatz, Korth and Sudarshan
6.*
Database System Concepts - 6th Edition
Update ExamplesMake interest payments by increasing all
balances by 5 percent. Pay all accounts with balances over
$10,000 6 percent interest
and pay all others 5 percent
r, branch_name, balance * 1.06
(account)
©Silberschatz, Korth and Sudarshan
6.*
Database System Concepts - 6th Edition
Example QueriesFind the name of all customers who have a
loan at the bank and the loan amountFind the names of all
customers who have a loan and an account at bank.
(depositor)
©Silberschatz, Korth and Sudarshan
6.*
Database System Concepts - 6th Edition
Example QueriesFind all customers who have an account from
at least the “Downtown” and the Uptown” branches.Query 1
account))
Query 2
wntown” ),
(“Uptown” )})
Note that Query 2 uses a constant relation.
©Silberschatz, Korth and Sudarshan
6.*
Database System Concepts - 6th Edition
Bank Example QueriesFind all customers who have an account
at all branches located in Brooklyn city.
)
(
,
,
2
,
1
r
k
A
A
A
K
Õ
)
(
,...,
,
2
1
E
n
F
F
F
Õ
)
(
)
,...,
2
,
1
(
E
n
A
A
A
x
r
)
(
)
(
,
,
(
),
(
,
,
,
2
2
1
1
2
1
E
n
n
n
A
F
A
F
A
F
G
G
G
K
K
g
)
(
,
,
,
,
2
1
r
r
l
F
F
F
K
Õ
¬
)
(
)
(
,
,
(
),
(
,
,
,
2
2
1
1
2
1
E
n
n
n
A
F
A
F
A
F
G
G
G
K
K
Database System Concepts, 6th Ed.
©Silberschatz, Korth and Sudarshan
See www.db-book.com for conditions on re-use
Chapter 1: Introduction
*
©Silberschatz, Korth and Sudarshan
1.*
Database System Concepts - 6th Edition
Database Management System (DBMS)DBMS contains
information about a particular enterpriseCollection of
interrelated dataSet of programs to access the data An
environment that is both convenient and efficient to
useDatabase Applications:Banking: transactionsAirlines:
reservations, schedulesUniversities: registration, gradesSales:
customers, products, purchasesOnline retailers: order tracking,
customized recommendationsManufacturing: production,
inventory, orders, supply chainHuman resources: employee
records, salaries, tax deductionsDatabases can be very
large.Databases touch all aspects of our lives
*
©Silberschatz, Korth and Sudarshan
1.*
Database System Concepts - 6th Edition
University Database ExampleApplication program examplesAdd
new students, instructors, and coursesRegister students for
courses, and generate class rostersAssign grades to students,
compute grade point averages (GPA) and generate transcriptsIn
the early days, database applications were built directly on top
of file systems
*
©Silberschatz, Korth and Sudarshan
1.*
Database System Concepts - 6th Edition
Drawbacks of using file systems to store data
Data redundancy and inconsistencyMultiple file formats,
duplication of information in different filesDifficulty in
accessing data Need to write a new program to carry out each
new taskData isolation — multiple files and formatsIntegrity
problemsIntegrity constraints (e.g., account balance > 0)
become “buried” in program code rather than being stated
explicitlyHard to add new constraints or change existing ones
*
©Silberschatz, Korth and Sudarshan
1.*
Database System Concepts - 6th Edition
Drawbacks of using file systems to store data (Cont.)
Atomicity of updatesFailures may leave database in an
inconsistent state with partial updates carried outExample:
Transfer of funds from one account to another should either
complete or not happen at allConcurrent access by multiple
usersConcurrent access needed for performanceUncontrolled
concurrent accesses can lead to inconsistencies
Example: Two people reading a balance (say 100) and updating
it by withdrawing money (say 50 each) at the same timeSecurity
problemsHard to provide user access to some, but not all, data
Database systems offer solutions to all the above problems
*
©Silberschatz, Korth and Sudarshan
1.*
Database System Concepts - 6th Edition
Levels of AbstractionPhysical level: describes how a record
(e.g., customer) is stored.Logical level: describes data stored in
database, and the relationships among the data.
type instructor = record
ID : string;
name : string;
dept_name : string;
salary : integer;
end;View level: application programs hide details of data types.
Views can also hide information (such as an employee’s salary)
for security purposes.
*
©Silberschatz, Korth and Sudarshan
1.*
Database System Concepts - 6th Edition
View of Data
An architecture for a database system
*
©Silberschatz, Korth and Sudarshan
1.*
Database System Concepts - 6th Edition
Instances and SchemasSimilar to types and variables in
programming languagesSchema – the logical structure of the
database Example: The database consists of information about a
set of customers and accounts and the relationship between
themAnalogous to type information of a variable in a
programPhysical schema: database design at the physical
levelLogical schema: database design at the logical
levelInstance – the actual content of the database at a particular
point in time Analogous to the value of a variablePhysical Data
Independence – the ability to modify the physical schema
without changing the logical schemaApplications depend on the
logical schemaIn general, the interfaces between the various
levels and components should be well defined so that changes in
some parts do not seriously influence others.
*
©Silberschatz, Korth and Sudarshan
1.*
Database System Concepts - 6th Edition
Data ModelsA collection of tools for describing Data Data
relationshipsData semanticsData constraintsRelational
modelEntity-Relationship data model (mainly for database
design) Object-based data models (Object-oriented and Object-
relational)Semistructured data model (XML)Other older
models:Network model Hierarchical model
*
©Silberschatz, Korth and Sudarshan
1.*
Database System Concepts - 6th Edition
Relational ModelRelational model (Chapter 2)Example of
tabular data in the relational model
Columns
Rows
*
©Silberschatz, Korth and Sudarshan
1.*
Database System Concepts - 6th Edition
A Sample Relational Database
*
©Silberschatz, Korth and Sudarshan
1.*
Database System Concepts - 6th Edition
Data Manipulation Language (DML)Language for accessing and
manipulating the data organized by the appropriate data
modelDML also known as query languageTwo classes of
languages Procedural – user specifies what data is required and
how to get those data Declarative (nonprocedural) – user
specifies what data is required without specifying how to get
those dataSQL is the most widely used query language
*
©Silberschatz, Korth and Sudarshan
1.*
Database System Concepts - 6th Edition
Data Definition Language (DDL)Specification notation for
defining the database schema
Example: create table instructor (
ID char(5),
name varchar(20),
dept_name varchar(20),
salary numeric(8,2))DDL compiler
generates a set of table templates stored in a data
dictionaryData dictionary contains metadata (i.e., data about
data)Database schema Integrity constraintsPrimary key (ID
uniquely identifies instructors)Referential integrity (references
constraint in SQL)
e.g. dept_name value in any instructor tuple must appear in
department relationAuthorization
*
©Silberschatz, Korth and Sudarshan
1.*
Database System Concepts - 6th Edition
SQLSQL: widely used non-procedural languageExample: Find
the name of the instructor with ID 22222
select name
from instructor
where instructor.ID = ‘22222’Example: Find the ID
and building of instructors in the Physics dept.
select instructor.ID, department.building
from instructor, department
where instructor.dept_name = department.dept_name and
department.dept_name = ‘Physics’
Application programs generally access databases through one
ofLanguage extensions to allow embedded SQLApplication
program interface (e.g., ODBC/JDBC) which allow SQL queries
to be sent to a databaseChapters 3, 4 and 5
*
©Silberschatz, Korth and Sudarshan
1.*
Database System Concepts - 6th Edition
Database Design
The process of designing the general structure of the database:
Logical Design – Deciding on the database schema. Database
design requires that we find a “good” collection of relation
schemas.Business decision – What attributes should we record
in the database?Computer Science decision – What relation
schemas should we have and how should the attributes be
distributed among the various relation schemas?
Physical Design – Deciding on the physical layout of the
database
*
©Silberschatz, Korth and Sudarshan
1.*
Database System Concepts - 6th Edition
Database Design?Is there any problem with this design?
*
©Silberschatz, Korth and Sudarshan
1.*
Database System Concepts - 6th Edition
Design ApproachesNormalization Theory (Chapter 8)Formalize
what designs are bad, and test for themEntity Relationship
Model (Chapter 7)Models an enterprise as a collection of
entities and relationshipsEntity: a “thing” or “object” in the
enterprise that is distinguishable from other objects
Described by a set of attributesRelationship: an association
among several entitiesRepresented diagrammatically by an
entity-relationship diagram:
*
©Silberschatz, Korth and Sudarshan
1.*
Database System Concepts - 6th Edition
The Entity-Relationship ModelModels an enterprise as a
collection of entities and relationshipsEntity: a “thing” or
“object” in the enterprise that is distinguishable from other
objectsDescribed by a set of attributesRelationship: an
association among several entitiesRepresented diagrammatically
by an entity-relationship diagram:
What happened to dept_name of instructor and student?
*
©Silberschatz, Korth and Sudarshan
1.*
Database System Concepts - 6th Edition
Object-Relational Data ModelsRelational model: flat, “atomic”
valuesObject Relational Data ModelsExtend the relational data
model by including object orientation and constructs to deal
with added data types.Allow attributes of tuples to have
complex types, including non-atomic values such as nested
relations.Preserve relational foundations, in particular the
declarative access to data, while extending modeling
power.Provide upward compatibility with existing relational
languages.
*
©Silberschatz, Korth and Sudarshan
1.*
Database System Concepts - 6th Edition
XML: Extensible Markup LanguageDefined by the WWW
Consortium (W3C)Originally intended as a document markup
language not a database languageThe ability to specify new
tags, and to create nested tag structures made XML a great way
to exchange data, not just documentsXML has become the basis
for all new generation data interchange formats.A wide variety
of tools is available for parsing, browsing and querying XML
documents/data
*
©Silberschatz, Korth and Sudarshan
1.*
Database System Concepts - 6th Edition
Storage ManagementStorage manager is a program module that
provides the interface between the low-level data stored in the
database and the application programs and queries submitted to
the system.The storage manager is responsible to the following
tasks: Interaction with the file manager Efficient storing,
retrieving and updating of dataIssues:Storage accessFile
organizationIndexing and hashing
*
©Silberschatz, Korth and Sudarshan
1.*
Database System Concepts - 6th Edition
Query Processing
1. Parsing and translation
2. Optimization
3. Evaluation
*
©Silberschatz, Korth and Sudarshan
1.*
Database System Concepts - 6th Edition
Query Processing (Cont.)Alternative ways of evaluating a given
queryEquivalent expressionsDifferent algorithms for each
operationCost difference between a good and a bad way of
evaluating a query can be enormousNeed to estimate the cost of
operationsDepends critically on statistical information about
relations which the database must maintainNeed to estimate
statistics for intermediate results to compute cost of complex
expressions
*
©Silberschatz, Korth and Sudarshan
1.*
Database System Concepts - 6th Edition
Transaction Management What if the system fails?What if more
than one user is concurrently updating the same data?A
transaction is a collection of operations that performs a single
logical function in a database applicationTransaction-
management component ensures that the database remains in a
consistent (correct) state despite system failures (e.g., power
failures and operating system crashes) and transaction
failures.Concurrency-control manager controls the interaction
among the concurrent transactions, to ensure the consistency of
the database.
*
©Silberschatz, Korth and Sudarshan
1.*
Database System Concepts - 6th Edition
Database Users and Administrators
Database
*
©Silberschatz, Korth and Sudarshan
1.*
Database System Concepts - 6th Edition
Database System Internals
*
©Silberschatz, Korth and Sudarshan
1.*
Database System Concepts - 6th Edition
Database Architecture
The architecture of a database systems is greatly influenced by
the underlying computer system on which the database is
running:CentralizedClient-serverParallel (multi-
processor)Distributed
*
©Silberschatz, Korth and Sudarshan
1.*
Database System Concepts - 6th Edition
History of Database Systems1950s and early 1960s:Data
processing using magnetic tapes for storageTapes provided only
sequential accessPunched cards for inputLate 1960s and
1970s:Hard disks allowed direct access to dataNetwork and
hierarchical data models in widespread useTed Codd defines the
relational data modelWould win the ACM Turing Award for this
workIBM Research begins System R prototypeUC Berkeley
begins Ingres prototypeHigh-performance (for the era)
transaction processing
*
©Silberschatz, Korth and Sudarshan
1.*
Database System Concepts - 6th Edition
History (cont.)1980s:Research relational prototypes evolve into
commercial systemsSQL becomes industrial standardParallel
and distributed database systemsObject-oriented database
systems1990s:Large decision support and data-mining
applicationsLarge multi-terabyte data warehousesEmergence of
Web commerceEarly 2000s:XML and XQuery
standardsAutomated database administrationLater 2000s:Giant
data storage systemsGoogle BigTable, Yahoo PNuts, Amazon, ..
*
©Silberschatz, Korth and Sudarshan
1.*
Database System Concepts - 6th Edition
End of Chapter 1
*
©Silberschatz, Korth and Sudarshan
1.*
Database System Concepts - 6th Edition
Figure 1.02
*
©Silberschatz, Korth and Sudarshan
1.*
Database System Concepts - 6th Edition
Figure 1.04
*
©Silberschatz, Korth and Sudarshan
1.*
Database System Concepts - 6th Edition
Figure 1.06
*
Database System Concepts, 6th Ed.
©Silberschatz, Korth and Sudarshan
See www.db-book.com for conditions on re-use
Chapter 2: Intro to Relational Model
*
©Silberschatz, Korth and Sudarshan
2.*
Database System Concepts - 6th Edition
Example of a Relation
attributes
(or columns)
tuples
(or rows)
*
©Silberschatz, Korth and Sudarshan
2.*
Database System Concepts - 6th Edition
Attribute TypesThe set of allowed values for each attribute is
called the domain of the attributeAttribute values are (normally)
required to be atomic; that is, indivisibleThe special value null
is a member of every domainThe null value causes
complications in the definition of many operations
*
©Silberschatz, Korth and Sudarshan
2.*
Database System Concepts - 6th Edition
Relation Schema and InstanceA1, A2, …, An are attributes
R = (A1, A2, …, An ) is a relation schema
Example:
instructor = (ID, name, dept_name, salary)Formally,
given sets D1, D2, …. Dn a relation r is a subset of
D1 x D2 x … x Dn
Thus, a relation is a set of n-tuples (a1, a2, …, an) where each
The current values (relation instance) of a relation are specified
by a tableAn element t of r is a tuple, represented by a row in a
table
*
©Silberschatz, Korth and Sudarshan
2.*
Database System Concepts - 6th Edition
Relations are Unordered Order of tuples is irrelevant (tuples
may be stored in an arbitrary order) Example: instructor relation
with unordered tuples
*
©Silberschatz, Korth and Sudarshan
2.*
Database System Concepts - 6th Edition
DatabaseA database consists of multiple relationsInformation
about an enterprise is broken up into parts
instructor
student
advisorBad design:
univ (instructor -ID, name, dept_name, salary, student_Id,
..)
results inrepetition of information (e.g., two students have the
same instructor)the need for null values (e.g., represent an
student with no advisor)Normalization theory (Chapter 7) deals
with how to design “good” relational schemas
*
©Silberschatz, Korth and Sudarshan
2.*
Database System Concepts - 6th Edition
sufficient to identify a unique tuple of each possible relation
r(R) Example: {ID} and {ID,name} are both superkeys of
instructor.Superkey K is a candidate key if K is minimal
Example: {ID} is a candidate key for InstructorOne of the
candidate keys is selected to be the primary key.which
one?Foreign key constraint: Value in one relation must appear
in anotherReferencing relationReferenced relation
*
©Silberschatz, Korth and Sudarshan
2.*
Database System Concepts - 6th Edition
Schema Diagram for University Database
©Silberschatz, Korth and Sudarshan
2.*
Database System Concepts - 6th Edition
Relational Query LanguagesProcedural vs.non-procedural, or
declarative“Pure” languages:Relational algebraTuple relational
calculusDomain relational calculusRelational operators
*
©Silberschatz, Korth and Sudarshan
2.*
Database System Concepts - 6th Edition
Selection of tuplesRelation rSelect tuples with A=B and D > 5σ
A=B and D > 5 (r)
*
©Silberschatz, Korth and Sudarshan
2.*
Database System Concepts - 6th Edition
Selection of Columns (Attributes)Relation r:
Select A and CProjectionΠ A, C (r)
*
©Silberschatz, Korth and Sudarshan
2.*
Database System Concepts - 6th Edition
Joining two relations – Cartesian ProductRelations r, s:r x s:
*
©Silberschatz, Korth and Sudarshan
2.*
Database System Concepts - 6th Edition
Uni
*
©Silberschatz, Korth and Sudarshan
2.*
Database System Concepts - 6th Edition
Set difference of two relationsRelations r, s:r – s:
*
©Silberschatz, Korth and Sudarshan
2.*
Database System Concepts - 6th Edition
Set Intersection of two relationsRelation r, s:
*
©Silberschatz, Korth and Sudarshan
2.*
Database System Concepts - 6th Edition
Joining two relations – Natural JoinLet r and s be relations on
schemas R and S respectively.
Then, the “natural join” of relations R and S is a relation on
tr from r and ts from s. If tr and ts have the same value on each
as
the same value as tr on rt has the same value as ts on s
*
©Silberschatz, Korth and Sudarshan
2.*
Database System Concepts - 6th Edition
Natural Join ExampleRelations r, s:
Natural Joinr s
*
©Silberschatz, Korth and Sudarshan
2.*
Database System Concepts - 6th Edition
Figure in-2.1
*
Database System Concepts, 6th Ed.
©Silberschatz, Korth and Sudarshan
See www.db-book.com for conditions on re-use
End of Chapter 2
*
©Silberschatz, Korth and Sudarshan
2.*
Database System Concepts - 6th Edition
Figure 2.01
*
©Silberschatz, Korth and Sudarshan
2.*
Database System Concepts - 6th Edition
Figure 2.02
*
©Silberschatz, Korth and Sudarshan
2.*
Database System Concepts - 6th Edition
Figure 2.03
*
©Silberschatz, Korth and Sudarshan
2.*
Database System Concepts - 6th Edition
Figure 2.04
*
©Silberschatz, Korth and Sudarshan
2.*
Database System Concepts - 6th Edition
Figure 2.05
*
©Silberschatz, Korth and Sudarshan
2.*
Database System Concepts - 6th Edition
Figure 2.06
*
©Silberschatz, Korth and Sudarshan
2.*
Database System Concepts - 6th Edition
Figure 2.07
*
©Silberschatz, Korth and Sudarshan
2.*
Database System Concepts - 6th Edition
Figure 2.10
*
©Silberschatz, Korth and Sudarshan
2.*
Database System Concepts - 6th Edition
Figure 2.11
*
©Silberschatz, Korth and Sudarshan
2.*
Database System Concepts - 6th Edition
Figure 2.12
*
©Silberschatz, Korth and Sudarshan
2.*
Database System Concepts - 6th Edition
Figure 2.13
*
Pg. 03
Question Two
Assignment #1
Deadline: Day 04/10/2019 @ 23:59
[Total Mark for this Assignment is 5]
Fundamentals of Databases
IT403
College of Computing and Informatics
Question One
1 Mark
Learning Outcome(s): LO1
Describe fundamental data and database concepts
1. Give an example of 3 relations illustrating primary keys and
foreign keys.
Question Two
4 Marks
Learning Outcome(s): LO7
Use Structured Query Language to perform queries and to
perform relational operations.
Consider the following relations:
Student(sID, surName, firstName, campus, email)
Course(dept, cNum, name)
Offering(oID, dept, cNum, term, instructor)
Took(sID, oID, grade)
Such as:
Offering[dept, cNum] ⊆ Course[dept, cNum]
Took[sID] ⊆ Student[sID]
Took[oID] ⊆ Offering[oID]
Answer the following query using relational algebra:
1. Give the Student number of all students who have taken the
course number “343” by the department “CS”.
2. Find sID of all students who have earned some grade over 80
and some grade below 50.
3. Find the Terms when the course number “369” by the
department “CS” was not offered.
4. Find the Department and course number of courses that have
never been offered.
Database System Concepts, 6th Ed.©Silberschatz, Korth and .docx

More Related Content

Similar to Database System Concepts, 6th Ed.©Silberschatz, Korth and .docx

Similar to Database System Concepts, 6th Ed.©Silberschatz, Korth and .docx (20)

03 Relational Databases.ppt
03 Relational Databases.ppt03 Relational Databases.ppt
03 Relational Databases.ppt
 
ch6.ppt
ch6.pptch6.ppt
ch6.ppt
 
Database System Concepts ch4.pdf
Database System Concepts ch4.pdfDatabase System Concepts ch4.pdf
Database System Concepts ch4.pdf
 
Relational database concept
Relational database conceptRelational database concept
Relational database concept
 
Ch6 formal relational query languages
Ch6 formal relational query languages Ch6 formal relational query languages
Ch6 formal relational query languages
 
Intro to Relational Model
Intro to Relational ModelIntro to Relational Model
Intro to Relational Model
 
Relational Model
Relational ModelRelational Model
Relational Model
 
DBMS-Ch7-MKB (1).pdf
DBMS-Ch7-MKB (1).pdfDBMS-Ch7-MKB (1).pdf
DBMS-Ch7-MKB (1).pdf
 
Ch7
Ch7Ch7
Ch7
 
Database Design E-R Model.pdf
Database Design E-R Model.pdfDatabase Design E-R Model.pdf
Database Design E-R Model.pdf
 
ch7-clean.ppt
ch7-clean.pptch7-clean.ppt
ch7-clean.ppt
 
Ch7
Ch7Ch7
Ch7
 
Database
DatabaseDatabase
Database
 
Sql.pptx
Sql.pptxSql.pptx
Sql.pptx
 
1b_query_optimization_sil_7ed_ch16.ppt
1b_query_optimization_sil_7ed_ch16.ppt1b_query_optimization_sil_7ed_ch16.ppt
1b_query_optimization_sil_7ed_ch16.ppt
 
Relational algebra.pptx
Relational algebra.pptxRelational algebra.pptx
Relational algebra.pptx
 
ch3.ppt
ch3.pptch3.ppt
ch3.ppt
 
Int_SQL.pdf
Int_SQL.pdfInt_SQL.pdf
Int_SQL.pdf
 
Ch7
Ch7Ch7
Ch7
 
ch3.ppt
ch3.pptch3.ppt
ch3.ppt
 

More from randyburney60861

Delusional DisordersPakistani hought ProcessesBACKGROUND.docx
Delusional DisordersPakistani hought ProcessesBACKGROUND.docxDelusional DisordersPakistani hought ProcessesBACKGROUND.docx
Delusional DisordersPakistani hought ProcessesBACKGROUND.docxrandyburney60861
 
Demand, Supply, and the Market ProcessGWARTNEY – STROUP .docx
Demand, Supply, and the Market ProcessGWARTNEY – STROUP .docxDemand, Supply, and the Market ProcessGWARTNEY – STROUP .docx
Demand, Supply, and the Market ProcessGWARTNEY – STROUP .docxrandyburney60861
 
Deloitte’s 2020 Global Blockchain SurveyFrom promise to re.docx
Deloitte’s 2020 Global Blockchain SurveyFrom promise to re.docxDeloitte’s 2020 Global Blockchain SurveyFrom promise to re.docx
Deloitte’s 2020 Global Blockchain SurveyFrom promise to re.docxrandyburney60861
 
DELL COMPANY’ Application of the accounting theories on the comp.docx
DELL COMPANY’ Application of the accounting theories on the comp.docxDELL COMPANY’ Application of the accounting theories on the comp.docx
DELL COMPANY’ Application of the accounting theories on the comp.docxrandyburney60861
 
Deliverable Length10–15 slides not including title and refere.docx
Deliverable Length10–15 slides not including title and refere.docxDeliverable Length10–15 slides not including title and refere.docx
Deliverable Length10–15 slides not including title and refere.docxrandyburney60861
 
Deliverable 6 - Using Business VisualsCompetencyExamine and de.docx
Deliverable 6 - Using Business VisualsCompetencyExamine and de.docxDeliverable 6 - Using Business VisualsCompetencyExamine and de.docx
Deliverable 6 - Using Business VisualsCompetencyExamine and de.docxrandyburney60861
 
Deliverable 5 - Hypothesis Tests for Two SamplesCompetencyForm.docx
Deliverable 5 - Hypothesis Tests for Two SamplesCompetencyForm.docxDeliverable 5 - Hypothesis Tests for Two SamplesCompetencyForm.docx
Deliverable 5 - Hypothesis Tests for Two SamplesCompetencyForm.docxrandyburney60861
 
Deliverable 5 - Proposed HR Initiatives PresentationAssignme.docx
Deliverable 5 - Proposed HR Initiatives PresentationAssignme.docxDeliverable 5 - Proposed HR Initiatives PresentationAssignme.docx
Deliverable 5 - Proposed HR Initiatives PresentationAssignme.docxrandyburney60861
 
Deliverable 4 - Diversity and Inclusion PolicyAssignment Con.docx
Deliverable 4 - Diversity and Inclusion PolicyAssignment Con.docxDeliverable 4 - Diversity and Inclusion PolicyAssignment Con.docx
Deliverable 4 - Diversity and Inclusion PolicyAssignment Con.docxrandyburney60861
 
Deliverable 4 - Global Environment ChallengesCompetencyC.docx
Deliverable 4 - Global Environment ChallengesCompetencyC.docxDeliverable 4 - Global Environment ChallengesCompetencyC.docx
Deliverable 4 - Global Environment ChallengesCompetencyC.docxrandyburney60861
 
Deliverable 03 - Humanities (Test-Out Sophia Replacement)Com.docx
Deliverable 03 - Humanities (Test-Out Sophia Replacement)Com.docxDeliverable 03 - Humanities (Test-Out Sophia Replacement)Com.docx
Deliverable 03 - Humanities (Test-Out Sophia Replacement)Com.docxrandyburney60861
 
Deliverable 03 - Humanities (Test-Out Sophia Replacement)Compete.docx
Deliverable 03 - Humanities (Test-Out Sophia Replacement)Compete.docxDeliverable 03 - Humanities (Test-Out Sophia Replacement)Compete.docx
Deliverable 03 - Humanities (Test-Out Sophia Replacement)Compete.docxrandyburney60861
 
DEFINITION a brief definition of the key term followed by t.docx
DEFINITION a brief definition of the key term followed by t.docxDEFINITION a brief definition of the key term followed by t.docx
DEFINITION a brief definition of the key term followed by t.docxrandyburney60861
 
Definition of HIVAIDS. What are the symptoms and general characteri.docx
Definition of HIVAIDS. What are the symptoms and general characteri.docxDefinition of HIVAIDS. What are the symptoms and general characteri.docx
Definition of HIVAIDS. What are the symptoms and general characteri.docxrandyburney60861
 
Definition of Ethos and How to Use it1. Trustworthiness
Does y.docx
Definition of Ethos and How to Use it1. Trustworthiness
Does y.docxDefinition of Ethos and How to Use it1. Trustworthiness
Does y.docx
Definition of Ethos and How to Use it1. Trustworthiness
Does y.docxrandyburney60861
 
Definition Multimodal refers to works that use a combination .docx
Definition Multimodal refers to works that use a combination .docxDefinition Multimodal refers to works that use a combination .docx
Definition Multimodal refers to works that use a combination .docxrandyburney60861
 
Definition Argument Essay AssignmentGoal Write a 1,500.docx
Definition Argument Essay AssignmentGoal Write a 1,500.docxDefinition Argument Essay AssignmentGoal Write a 1,500.docx
Definition Argument Essay AssignmentGoal Write a 1,500.docxrandyburney60861
 
DEFINITION a brief definition of the key term followed by the APA r.docx
DEFINITION a brief definition of the key term followed by the APA r.docxDEFINITION a brief definition of the key term followed by the APA r.docx
DEFINITION a brief definition of the key term followed by the APA r.docxrandyburney60861
 
Defining Privacy in Employee Health ScreeningCases Ethical .docx
Defining Privacy in Employee Health ScreeningCases Ethical .docxDefining Privacy in Employee Health ScreeningCases Ethical .docx
Defining Privacy in Employee Health ScreeningCases Ethical .docxrandyburney60861
 
Define      diversity” and inclusion” as applied to your pre.docx
Define      diversity” and inclusion” as applied to your pre.docxDefine      diversity” and inclusion” as applied to your pre.docx
Define      diversity” and inclusion” as applied to your pre.docxrandyburney60861
 

More from randyburney60861 (20)

Delusional DisordersPakistani hought ProcessesBACKGROUND.docx
Delusional DisordersPakistani hought ProcessesBACKGROUND.docxDelusional DisordersPakistani hought ProcessesBACKGROUND.docx
Delusional DisordersPakistani hought ProcessesBACKGROUND.docx
 
Demand, Supply, and the Market ProcessGWARTNEY – STROUP .docx
Demand, Supply, and the Market ProcessGWARTNEY – STROUP .docxDemand, Supply, and the Market ProcessGWARTNEY – STROUP .docx
Demand, Supply, and the Market ProcessGWARTNEY – STROUP .docx
 
Deloitte’s 2020 Global Blockchain SurveyFrom promise to re.docx
Deloitte’s 2020 Global Blockchain SurveyFrom promise to re.docxDeloitte’s 2020 Global Blockchain SurveyFrom promise to re.docx
Deloitte’s 2020 Global Blockchain SurveyFrom promise to re.docx
 
DELL COMPANY’ Application of the accounting theories on the comp.docx
DELL COMPANY’ Application of the accounting theories on the comp.docxDELL COMPANY’ Application of the accounting theories on the comp.docx
DELL COMPANY’ Application of the accounting theories on the comp.docx
 
Deliverable Length10–15 slides not including title and refere.docx
Deliverable Length10–15 slides not including title and refere.docxDeliverable Length10–15 slides not including title and refere.docx
Deliverable Length10–15 slides not including title and refere.docx
 
Deliverable 6 - Using Business VisualsCompetencyExamine and de.docx
Deliverable 6 - Using Business VisualsCompetencyExamine and de.docxDeliverable 6 - Using Business VisualsCompetencyExamine and de.docx
Deliverable 6 - Using Business VisualsCompetencyExamine and de.docx
 
Deliverable 5 - Hypothesis Tests for Two SamplesCompetencyForm.docx
Deliverable 5 - Hypothesis Tests for Two SamplesCompetencyForm.docxDeliverable 5 - Hypothesis Tests for Two SamplesCompetencyForm.docx
Deliverable 5 - Hypothesis Tests for Two SamplesCompetencyForm.docx
 
Deliverable 5 - Proposed HR Initiatives PresentationAssignme.docx
Deliverable 5 - Proposed HR Initiatives PresentationAssignme.docxDeliverable 5 - Proposed HR Initiatives PresentationAssignme.docx
Deliverable 5 - Proposed HR Initiatives PresentationAssignme.docx
 
Deliverable 4 - Diversity and Inclusion PolicyAssignment Con.docx
Deliverable 4 - Diversity and Inclusion PolicyAssignment Con.docxDeliverable 4 - Diversity and Inclusion PolicyAssignment Con.docx
Deliverable 4 - Diversity and Inclusion PolicyAssignment Con.docx
 
Deliverable 4 - Global Environment ChallengesCompetencyC.docx
Deliverable 4 - Global Environment ChallengesCompetencyC.docxDeliverable 4 - Global Environment ChallengesCompetencyC.docx
Deliverable 4 - Global Environment ChallengesCompetencyC.docx
 
Deliverable 03 - Humanities (Test-Out Sophia Replacement)Com.docx
Deliverable 03 - Humanities (Test-Out Sophia Replacement)Com.docxDeliverable 03 - Humanities (Test-Out Sophia Replacement)Com.docx
Deliverable 03 - Humanities (Test-Out Sophia Replacement)Com.docx
 
Deliverable 03 - Humanities (Test-Out Sophia Replacement)Compete.docx
Deliverable 03 - Humanities (Test-Out Sophia Replacement)Compete.docxDeliverable 03 - Humanities (Test-Out Sophia Replacement)Compete.docx
Deliverable 03 - Humanities (Test-Out Sophia Replacement)Compete.docx
 
DEFINITION a brief definition of the key term followed by t.docx
DEFINITION a brief definition of the key term followed by t.docxDEFINITION a brief definition of the key term followed by t.docx
DEFINITION a brief definition of the key term followed by t.docx
 
Definition of HIVAIDS. What are the symptoms and general characteri.docx
Definition of HIVAIDS. What are the symptoms and general characteri.docxDefinition of HIVAIDS. What are the symptoms and general characteri.docx
Definition of HIVAIDS. What are the symptoms and general characteri.docx
 
Definition of Ethos and How to Use it1. Trustworthiness
Does y.docx
Definition of Ethos and How to Use it1. Trustworthiness
Does y.docxDefinition of Ethos and How to Use it1. Trustworthiness
Does y.docx
Definition of Ethos and How to Use it1. Trustworthiness
Does y.docx
 
Definition Multimodal refers to works that use a combination .docx
Definition Multimodal refers to works that use a combination .docxDefinition Multimodal refers to works that use a combination .docx
Definition Multimodal refers to works that use a combination .docx
 
Definition Argument Essay AssignmentGoal Write a 1,500.docx
Definition Argument Essay AssignmentGoal Write a 1,500.docxDefinition Argument Essay AssignmentGoal Write a 1,500.docx
Definition Argument Essay AssignmentGoal Write a 1,500.docx
 
DEFINITION a brief definition of the key term followed by the APA r.docx
DEFINITION a brief definition of the key term followed by the APA r.docxDEFINITION a brief definition of the key term followed by the APA r.docx
DEFINITION a brief definition of the key term followed by the APA r.docx
 
Defining Privacy in Employee Health ScreeningCases Ethical .docx
Defining Privacy in Employee Health ScreeningCases Ethical .docxDefining Privacy in Employee Health ScreeningCases Ethical .docx
Defining Privacy in Employee Health ScreeningCases Ethical .docx
 
Define      diversity” and inclusion” as applied to your pre.docx
Define      diversity” and inclusion” as applied to your pre.docxDefine      diversity” and inclusion” as applied to your pre.docx
Define      diversity” and inclusion” as applied to your pre.docx
 

Recently uploaded

Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxContemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxRoyAbrique
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 
Class 11 Legal Studies Ch-1 Concept of State .pdf
Class 11 Legal Studies Ch-1 Concept of State .pdfClass 11 Legal Studies Ch-1 Concept of State .pdf
Class 11 Legal Studies Ch-1 Concept of State .pdfakmcokerachita
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentInMediaRes1
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting DataJhengPantaleon
 
Science 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsScience 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsKarinaGenton
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application ) Sakshi Ghasle
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxGaneshChakor2
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxmanuelaromero2013
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxpboyjonauth
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformChameera Dedduwage
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
 

Recently uploaded (20)

Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxContemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
Class 11 Legal Studies Ch-1 Concept of State .pdf
Class 11 Legal Studies Ch-1 Concept of State .pdfClass 11 Legal Studies Ch-1 Concept of State .pdf
Class 11 Legal Studies Ch-1 Concept of State .pdf
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media Component
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
 
Science 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsScience 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its Characteristics
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application )
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptx
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptx
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptx
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 
9953330565 Low Rate Call Girls In Rohini Delhi NCR
9953330565 Low Rate Call Girls In Rohini  Delhi NCR9953330565 Low Rate Call Girls In Rohini  Delhi NCR
9953330565 Low Rate Call Girls In Rohini Delhi NCR
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
 

Database System Concepts, 6th Ed.©Silberschatz, Korth and .docx

  • 1. Database System Concepts, 6th Ed. ©Silberschatz, Korth and Sudarshan See www.db-book.com for conditions on re-use Chapter 6: Formal Relational Query Languages ©Silberschatz, Korth and Sudarshan 6.* Database System Concepts - 6th Edition Chapter 6: Formal Relational Query LanguagesRelational AlgebraTuple Relational CalculusDomain Relational Calculus ©Silberschatz, Korth and Sudarshan 6.* Database System Concepts - 6th Edition Relational AlgebraProcedural languageSix basic operators – Cartesian inputs and produce a new relation as a result.
  • 2. ©Silberschatz, Korth and Sudarshan 6.* Database System Concepts - 6th Edition Select Operation – ©Silberschatz, Korth and Sudarshan 6.* Database System Concepts - 6th Edition predicateDefined as: Where p is a formula in propositional calculus consisting Each term is one of: <attribute> op <attribute> or <constant> Example of selection: structor)
  • 3. ©Silberschatz, Korth and Sudarshan 6.* Database System Concepts - 6th Edition Project Operation – ExampleRelation r: ©Silberschatz, Korth and Sudarshan 6.* Database System Concepts - 6th Edition Project OperationNotation: where A1, A2 are attribute names and r is a relation name.The result is defined as the relation of k columns obtained by erasing the columns that are not listedDuplicate rows removed from result, since relations are setsExample: To eliminate the dept_name attribute of instructor
  • 4. ©Silberschatz, Korth and Sudarshan 6.* Database System Concepts - 6th Edition Union Operation – ©Silberschatz, Korth and Sudarshan 6.* Database System Concepts - 6th Edition 1. r, s must have the same arity (same number of attributes) 2. The attribute domains must be compatible (example: 2nd column of r deals with the same type of values as does the 2nd column of s)Example: to find all courses taught in the Fall 2009 semester, or in the Spring 2010 semester, or in both
  • 5. ©Silberschatz, Korth and Sudarshan 6.* Database System Concepts - 6th Edition Set difference of two relationsRelations r, s:r – s: ©Silberschatz, Korth and Sudarshan 6.* Database System Concepts - 6th Edition Set Difference OperationNotation r – sDefined as: r – Set differences must be taken between compatible relations.r and s must have the same arityattribute domains of r and s must be compatibleExample: to find all courses taught in the Fall 2009 semester, but not in the Spring 2010 semester ©Silberschatz, Korth and Sudarshan 6.* Database System Concepts - 6th Edition
  • 6. Cartesian-Product Operation – ExampleRelations r, s:r x s: ©Silberschatz, Korth and Sudarshan 6.* Database System Concepts - 6th Edition Cartesian-Product OperationNotation r x sDefined as: r x s = {t Assume that attributes of r(R) and s(S) are disjoint. (That is, R renaming must be used. ©Silberschatz, Korth and Sudarshan 6.* Database System Concepts - 6th Edition Composition of OperationsCan build expressions using multiple r x s
  • 7. ©Silberschatz, Korth and Sudarshan 6.* Database System Concepts - 6th Edition Rename OperationAllows us to name, and therefore to refer to, the results of relational-algebra expressions.Allows us to refer to a relation by more than one name.Example: returns the expression E under the name XIf a relational- algebra expression E has arity n, then returns the result of expression E under the name X, and with the attributes renamed to A1 , A2 , …., An . ©Silberschatz, Korth and Sudarshan 6.* Database System Concepts - 6th Edition Example QueryFind the largest salary in the universityStep 1: find instructor salaries that are less than some other instructor salary (i.e. not maximum)
  • 8. Find t – ©Silberschatz, Korth and Sudarshan 6.* Database System Concepts - 6th Edition Example QueriesFind the names of all instructors in the Physics department, along with the course_id of all courses they have taughtQuery 1 teaches)))Query 2 ©Silberschatz, Korth and Sudarshan 6.* Database System Concepts - 6th Edition Formal DefinitionA basic expression in the relational algebra
  • 9. consists of either one of the following:A relation in the databaseA constant relationLet E1 and E2 be relational-algebra expressions; the following are all relational-algebra – ate ©Silberschatz, Korth and Sudarshan 6.* Database System Concepts - 6th Edition Additional Operations We define additional operations that do not add any power to the relational algebra, but that simplify common queries.Set intersectionNatural joinAssignmentOuter join ©Silberschatz, Korth and Sudarshan 6.* Database System Concepts - 6th Edition Set-Intersection Ope – (r – s)
  • 10. ©Silberschatz, Korth and Sudarshan 6.* Database System Concepts - 6th Edition Set-Intersection Operation – ExampleRelation r, s: ©Silberschatz, Korth and Sudarshan 6.* Database System Concepts - 6th Edition Natural-Join OperationLet r and s be relations on schemas R and S respectively. Then, r s is a relation on schema R follows:Consider each pair of tuples tr from r and ts from s. If add a tuple t to the result, wheret has the same value as tr on rt has the same value as ts on sExample: R = (A, B, C, D) S = (E, B, D)Result schema = (A, B, C, D, E)r s is defined as: Notation: r s
  • 11. ©Silberschatz, Korth and Sudarshan 6.* Database System Concepts - 6th Edition Natural Join ExampleRelations r, s:r s ©Silberschatz, Korth and Sudarshan 6.* Database System Concepts - 6th Edition Natural Join and Theta JoinFind the names of all instructors in the Comp. Sci. department together with the course titles of all dept_name=“Comp. Sci.” (instructor teaches course))Natural join is associative(instructor teaches) course is equivalent to instructor (teaches course)Natural join is commutativeinstruct teaches is equivalent to ©Silberschatz, Korth and Sudarshan 6.* Database System Concepts - 6th Edition
  • 12. Assignment Operati convenient way to express complex queries. Write query as a sequential program consisting ofa series of assignments followed by an expression whose value is displayed as a result of the query.Assignment must always be made to a temporary relation variable. ©Silberschatz, Korth and Sudarshan 6.* Database System Concepts - 6th Edition Outer JoinAn extension of the join operation that avoids loss of information.Computes the join and then adds tuples form one relation that does not match tuples in the other relation to the result of the join. Uses null values:null signifies that the value is unknown or does not exist All comparisons involving null are (roughly speaking) false by definition.We shall study precise meaning of comparisons with nulls later ©Silberschatz, Korth and Sudarshan 6.* Database System Concepts - 6th Edition Outer Join – ExampleRelation instructor1Relation teaches1 ID course_id 10101
  • 13. 12121 76766 CS-101 FIN-201 BIO-101 Comp. Sci. Finance Music ID dept_name 10101 12121 15151 name Srinivasan Wu Mozart ©Silberschatz, Korth and Sudarshan 6.* Database System Concepts - 6th Edition Outer Join – ExampleJoin instructor teaches Left Outer Join instructor teaches ID dept_name 10101 12121 Comp. Sci.
  • 15. Full Outer Join instructor teaches Right Outer Join instructor teaches ID dept_name 10101 12121 76766 Comp. Sci. Finance null course_id CS-101 FIN-201 BIO-101 name Srinivasan Wu null ID dept_name 10101 12121 15151 76766 Comp. Sci. Finance Music null course_id CS-101 FIN-201 null BIO-101 name Srinivasan
  • 16. Wu Mozart null ©Silberschatz, Korth and Sudarshan 6.* Database System Concepts - 6th Edition Outer Join using JoinsOuter join can be expressed using basic operationse.g. r s can be written as (r s) U (r – ∏R(r s) x {(null, …, null)} ©Silberschatz, Korth and Sudarshan 6.* Database System Concepts - 6th Edition Null ValuesIt is possible for tuples to have a null value, denoted by null, for some of their attributesnull signifies an unknown value or that a value does not exist.The result of any arithmetic expression involving null is null.Aggregate functions simply
  • 17. ignore null values (as in SQL)For duplicate elimination and grouping, null is treated like any other value, and two nulls are assumed to be the same (as in SQL) ©Silberschatz, Korth and Sudarshan 6.* Database System Concepts - 6th Edition Null ValuesComparisons with null values return the special truth value: unknownIf false was used instead of unknown, then not (A < 5) would not be equivalent to A >= 5Three- valued logic using the truth value unknown:OR: (unknown or true) = true, (unknown or false) = unknown (unknown or unknown) = unknownAND: (true and unknown) = unknown, (false and unknown) = false, (unknown and unknown) = unknownNOT: (not unknown) = unknownIn SQL “P is unknown” evaluates to true if predicate P evaluates to unknownResult of select predicate is treated as false if it evaluates to unknown
  • 18. ©Silberschatz, Korth and Sudarshan 6.* Database System Concepts - 6th Edition Division OperatorGiven -S) such that (takes ) and then r -S (r ) -S ((temp1 x s ) – -S,S (r )) result = temp1 – is assigned to the relation variable variable in subsequent expressions. ©Silberschatz, Korth and Sudarshan 6.* Database System Concepts - 6th Edition Extended Relational-Algebra-OperationsGeneralized ProjectionAggregate Functions
  • 19. ©Silberschatz, Korth and Sudarshan 6.* Database System Concepts - 6th Edition Generalized ProjectionExtends the projection operation by allowing arithmetic functions to be used in the projection list. E is any relational-algebra expressionEach of F1, F2, …, Fn are are arithmetic expressions involving constants and attributes in the schema of E.Given relation instructor(ID, name, dept_name, salary) where salary is annual salary, get the same information but with monthly salary ©Silberschatz, Korth and Sudarshan 6.* Database System Concepts - 6th Edition Aggregate Functions and OperationsAggregation function takes a collection of values and returns a single value as a result. avg: average value min: minimum value max: maximum value sum: sum of values
  • 20. count: number of valuesAggregate operation in relational algebra E is any relational-algebra expressionG1, G2 …, Gn is a list of attributes on which to group (can be empty)Each Fi is an aggregate functionEach Ai is an attribute nameNote: Some ©Silberschatz, Korth and Sudarshan 6.* Database System Concepts - 6th Edition Aggregate Operation – ExampleRelation r: A B C 7 7 3 10 sum(c) (r) sum(c )
  • 21. 27 ©Silberschatz, Korth and Sudarshan 6.* Database System Concepts - 6th Edition Aggregate Operation – ExampleFind the average salary in each department dept_name avg(salary) (instructor) avg_salary ©Silberschatz, Korth and Sudarshan 6.* Database System Concepts - 6th Edition Aggregate Functions (Cont.)Result of aggregation does not have a nameCan use rename operation to give it a nameFor convenience, we permit renaming as part of aggregate operation dept_name avg(salary) as avg_sal (instructor) ©Silberschatz, Korth and Sudarshan 6.*
  • 22. Database System Concepts - 6th Edition Modification of the DatabaseThe content of the database may be modified using the following operations:DeletionInsertionUpdatingAll these operations can be expressed using the assignment operator ©Silberschatz, Korth and Sudarshan 6.* Database System Concepts - 6th Edition Multiset Relational AlgebraPure relational algebra removes all duplicates e.g. after projectionMultiset relational algebra retains duplicates, to match SQL semanticsSQL duplicate retention was initially for efficiency, but is now a featureMultiset relational algebra defined as followsselection: has as many duplicates of a tuple as in the input, if the tuple satisfies the selectionprojection: one tuple per input tuple, even if it is a duplicatecross product: If there are m copies of t1 in r, and n copies of t2 in s, there are m x n copies of t1.t2 in r x sOther operators similarly defined E.g. union: m + n copies, intersection: min(m, n) copies difference: min(0, m – n) copies ©Silberschatz, Korth and Sudarshan 6.* Database System Concepts - 6th Edition SQL and Relational Algebraselect A1, A2, .. An
  • 23. from r1, r2, …, rm where P is equivalent to the following expression in multiset relational algebra sum(A3) from r1, r2, …, rm where P group by A1, A2 is equivalent to the following expression in multiset relational algebra ©Silberschatz, Korth and Sudarshan 6.* Database System Concepts - 6th Edition SQL and Relational AlgebraMore generally, the non-aggregated attributes in the select clause may be a subset of the group by attributes, in which case the equivalence is as follows: select A1, sum(A3) from r1, r2, …, rm where P group by A1, A2 is equivalent to the following expression in multiset relational algebra
  • 24. (r1 x r2 x .. x rm))) ©Silberschatz, Korth and Sudarshan 6.* Database System Concepts - 6th Edition Tuple Relational Calculus ©Silberschatz, Korth and Sudarshan 6.* Database System Concepts - 6th Edition Tuple Relational CalculusA nonprocedural query language, where each query is of the form {t | P (t ) }It is the set of all tuples t such that predicate P is true for tt is a tuple variable, t [A ] denotes the relation rP is a formula similar to that of the predicate calculus ©Silberschatz, Korth and Sudarshan 6.* Database System Concepts - 6th Edition Predicate Calculus Formula 1. Set of attributes and constants
  • 25. 2. 3. Se 4. 5. Set of quantifiers: such that predicate Q (t ) is true ©Silberschatz, Korth and Sudarshan 6.* Database System Concepts - 6th Edition Example QueriesFind the ID, name, dept_name, salary for instructors whose salary is greater than $80,000 As in the previous query, but output only the ID attribute value 80000)} Notice that a relation on schema (ID) is implicitly defined by the query
  • 26. ©Silberschatz, Korth and Sudarshan 6.* Database System Concepts - 6th Edition Example QueriesFind the names of all instructors whose department is in the Watson building Find the set of all courses taught in the Fall 2009 semester, or in the Spring 2010 semester, or both ©Silberschatz, Korth and Sudarshan 6.* Database System Concepts - 6th Edition Example Queries
  • 27. Find the set of all courses taught in the Fall 2009 semester, and in the Spring 2010 semester s [semester] = “Fal Find the set of all courses taught in the Fall 2009 semester, but not in the Spring 2010 semester ©Silberschatz, Korth and Sudarshan 6.* Database System Concepts - 6th Edition Safety of ExpressionsIt is possible to write tuple calculus domain of any attribute of relation r is infiniteTo guard against the problem, we restrict the set of allowable expressions to safe expressions.An expression {t | P (t )} in the tuple relational calculus is safe if every component of t appears in one of the relations, tuples, or constants that appear in PNOTE: this is
  • 28. not safe --- it defines an infinite set with attribute values that do not appear in any relation or tuples or constants in P. ©Silberschatz, Korth and Sudarshan 6.* Database System Concepts - 6th Edition Universal QuantificationFind all students who have taken all s [course_id] = u [course_id]))}Note that without the existential quantification on student, the above query would be unsafe if the Biology department has not offered any courses. ©Silberschatz, Korth and Sudarshan 6.* Database System Concepts - 6th Edition Domain Relational Calculus
  • 29. ©Silberschatz, Korth and Sudarshan 6.* Database System Concepts - 6th Edition Domain Relational CalculusA nonprocedural query language equivalent in power to the tuple relational calculusEach query is an expression of the form: x1, x2, …, xn represent domain variablesP represents a formula similar to that of the predicate calculus ©Silberschatz, Korth and Sudarshan 6.* Database System Concepts - 6th Edition Example QueriesFind the ID, name, dept_name, salary for instructors whose salary is greater than $80,000{< i, n, d, s> | < department is in the Watson building instructor ))}
  • 30. ©Silberschatz, Korth and Sudarshan 6.* Database System Concepts - 6th Edition Example Queries courses taught in the Fall 2009 semester, or in the Spring 2010 semester, or both This case can also be written as 2010))} Find the set of all courses taught in the Fall 2009 semester, and in the Spring 2010 semester
  • 31. ©Silberschatz, Korth and Sudarshan 6.* Database System Concepts - 6th Edition Safety of Expressions The expression: is safe if all of the following hold: All values that appear in tuples of the expression are values from dom (P ) (that is, the values appear either in P or in a tuple of a relation mentioned in P ). the subformula is true if and only if there is a value of x in dom (P1) such that P1(x ) is true. subformula is true if and only if P1(x ) is true for all values x from dom (P1). ©Silberschatz, Korth and Sudarshan 6.* Database System Concepts - 6th Edition Universal QuantificationFind all students who have taken all
  • 32. =“Biology” ))}Note that without the existential quantification on student, the above query would be unsafe if the Biology department has not offered any courses. * Above query fixes bug in page 246, last query Database System Concepts, 6th Ed. ©Silberschatz, Korth and Sudarshan See www.db-book.com for conditions on re-use End of Chapter 6 ©Silberschatz, Korth and Sudarshan 6.* Database System Concepts - 6th Edition Figure 6.01 ©Silberschatz, Korth and Sudarshan 6.* Database System Concepts - 6th Edition Figure 6.02
  • 33. ©Silberschatz, Korth and Sudarshan 6.* Database System Concepts - 6th Edition Figure 6.03 ©Silberschatz, Korth and Sudarshan 6.* Database System Concepts - 6th Edition Figure 6.04 ©Silberschatz, Korth and Sudarshan 6.* Database System Concepts - 6th Edition Figure 6.05
  • 34. ©Silberschatz, Korth and Sudarshan 6.* Database System Concepts - 6th Edition Figure 6.06 ©Silberschatz, Korth and Sudarshan 6.* Database System Concepts - 6th Edition Figure 6.07 ©Silberschatz, Korth and Sudarshan 6.* Database System Concepts - 6th Edition Figure 6.08
  • 35. ©Silberschatz, Korth and Sudarshan 6.* Database System Concepts - 6th Edition Figure 6.09 ©Silberschatz, Korth and Sudarshan 6.* Database System Concepts - 6th Edition Figure 6.10 ©Silberschatz, Korth and Sudarshan 6.* Database System Concepts - 6th Edition Figure 6.11 ©Silberschatz, Korth and Sudarshan 6.* Database System Concepts - 6th Edition
  • 36. Figure 6.12 ©Silberschatz, Korth and Sudarshan 6.* Database System Concepts - 6th Edition Figure 6.13 ©Silberschatz, Korth and Sudarshan 6.* Database System Concepts - 6th Edition Figure 6.14 ©Silberschatz, Korth and Sudarshan 6.* Database System Concepts - 6th Edition Figure 6.15
  • 37. ©Silberschatz, Korth and Sudarshan 6.* Database System Concepts - 6th Edition Figure 6.16 ©Silberschatz, Korth and Sudarshan 6.* Database System Concepts - 6th Edition Figure 6.17 ©Silberschatz, Korth and Sudarshan 6.* Database System Concepts - 6th Edition Figure 6.18
  • 38. ©Silberschatz, Korth and Sudarshan 6.* Database System Concepts - 6th Edition Figure 6.19 ©Silberschatz, Korth and Sudarshan 6.* Database System Concepts - 6th Edition Figure 6.20 ©Silberschatz, Korth and Sudarshan 6.* Database System Concepts - 6th Edition Figure 6.21 ©Silberschatz, Korth and Sudarshan
  • 39. 6.* Database System Concepts - 6th Edition DeletionA delete request is expressed similarly to a query, except instead of displaying tuples to the user, the selected tuples are removed from the database.Can delete only whole tuples; cannot delete values on only particular attributesA deletion is expressed in relational algebra by: – E where r is a relation and E is a relational algebra query. ©Silberschatz, Korth and Sudarshan 6.* Database System Concepts - 6th Edition Deletion ExamplesDelete all account records in the Perryridge branch. Delete all accounts at branches located in Needham. Delete all loan records with amount in the range of 0 to 50 – – branch ) – r2 – r3
  • 40. ©Silberschatz, Korth and Sudarshan 6.* Database System Concepts - 6th Edition InsertionTo insert data into a relation, we either:specify a tuple to be insertedwrite a query whose result is a set of tuples to be insertedin relational algebra, an insertion is expressed by: where r is a relation and E is a relational algebra expression.The insertion of a single tuple is expressed by letting E be a constant relation containing one tuple. ©Silberschatz, Korth and Sudarshan 6.* Database System Concepts - 6th Edition Insertion ExamplesInsert information in the database specifying that Smith has $1200 in account A-973 at the Perryridge branch. Provide as a gift for all loan customers in the Perryridge branch, a $200 savings account. Let the loan number serve as the account number for the new savings account. acc -973”, “Perryridge”, 1200)} -973”)} number (r1)
  • 41. ©Silberschatz, Korth and Sudarshan 6.* Database System Concepts - 6th Edition UpdatingA mechanism to change a value in a tuple without charging all values in the tupleUse the generalized projection operator to do this task Each Fi is either the I th attribute of r, if the I th attribute is not updated, or,if the attribute is to be updated Fi is an expression, involving only constants and the attributes of r, which gives the new value for the attribute ©Silberschatz, Korth and Sudarshan 6.* Database System Concepts - 6th Edition Update ExamplesMake interest payments by increasing all balances by 5 percent. Pay all accounts with balances over $10,000 6 percent interest and pay all others 5 percent r, branch_name, balance * 1.06 (account)
  • 42. ©Silberschatz, Korth and Sudarshan 6.* Database System Concepts - 6th Edition Example QueriesFind the name of all customers who have a loan at the bank and the loan amountFind the names of all customers who have a loan and an account at bank. (depositor) ©Silberschatz, Korth and Sudarshan 6.* Database System Concepts - 6th Edition Example QueriesFind all customers who have an account from at least the “Downtown” and the Uptown” branches.Query 1 account)) Query 2 wntown” ), (“Uptown” )}) Note that Query 2 uses a constant relation.
  • 43. ©Silberschatz, Korth and Sudarshan 6.* Database System Concepts - 6th Edition Bank Example QueriesFind all customers who have an account at all branches located in Brooklyn city. ) ( , , 2 , 1 r k A A A K Õ ) (
  • 47. K K Database System Concepts, 6th Ed. ©Silberschatz, Korth and Sudarshan See www.db-book.com for conditions on re-use Chapter 1: Introduction * ©Silberschatz, Korth and Sudarshan 1.* Database System Concepts - 6th Edition Database Management System (DBMS)DBMS contains information about a particular enterpriseCollection of interrelated dataSet of programs to access the data An environment that is both convenient and efficient to useDatabase Applications:Banking: transactionsAirlines: reservations, schedulesUniversities: registration, gradesSales: customers, products, purchasesOnline retailers: order tracking, customized recommendationsManufacturing: production, inventory, orders, supply chainHuman resources: employee records, salaries, tax deductionsDatabases can be very large.Databases touch all aspects of our lives *
  • 48. ©Silberschatz, Korth and Sudarshan 1.* Database System Concepts - 6th Edition University Database ExampleApplication program examplesAdd new students, instructors, and coursesRegister students for courses, and generate class rostersAssign grades to students, compute grade point averages (GPA) and generate transcriptsIn the early days, database applications were built directly on top of file systems * ©Silberschatz, Korth and Sudarshan 1.* Database System Concepts - 6th Edition Drawbacks of using file systems to store data Data redundancy and inconsistencyMultiple file formats, duplication of information in different filesDifficulty in accessing data Need to write a new program to carry out each new taskData isolation — multiple files and formatsIntegrity problemsIntegrity constraints (e.g., account balance > 0) become “buried” in program code rather than being stated explicitlyHard to add new constraints or change existing ones *
  • 49. ©Silberschatz, Korth and Sudarshan 1.* Database System Concepts - 6th Edition Drawbacks of using file systems to store data (Cont.) Atomicity of updatesFailures may leave database in an inconsistent state with partial updates carried outExample: Transfer of funds from one account to another should either complete or not happen at allConcurrent access by multiple usersConcurrent access needed for performanceUncontrolled concurrent accesses can lead to inconsistencies Example: Two people reading a balance (say 100) and updating it by withdrawing money (say 50 each) at the same timeSecurity problemsHard to provide user access to some, but not all, data Database systems offer solutions to all the above problems * ©Silberschatz, Korth and Sudarshan 1.* Database System Concepts - 6th Edition Levels of AbstractionPhysical level: describes how a record (e.g., customer) is stored.Logical level: describes data stored in database, and the relationships among the data. type instructor = record ID : string; name : string; dept_name : string;
  • 50. salary : integer; end;View level: application programs hide details of data types. Views can also hide information (such as an employee’s salary) for security purposes. * ©Silberschatz, Korth and Sudarshan 1.* Database System Concepts - 6th Edition View of Data An architecture for a database system * ©Silberschatz, Korth and Sudarshan 1.* Database System Concepts - 6th Edition Instances and SchemasSimilar to types and variables in programming languagesSchema – the logical structure of the database Example: The database consists of information about a set of customers and accounts and the relationship between themAnalogous to type information of a variable in a programPhysical schema: database design at the physical levelLogical schema: database design at the logical levelInstance – the actual content of the database at a particular point in time Analogous to the value of a variablePhysical Data
  • 51. Independence – the ability to modify the physical schema without changing the logical schemaApplications depend on the logical schemaIn general, the interfaces between the various levels and components should be well defined so that changes in some parts do not seriously influence others. * ©Silberschatz, Korth and Sudarshan 1.* Database System Concepts - 6th Edition Data ModelsA collection of tools for describing Data Data relationshipsData semanticsData constraintsRelational modelEntity-Relationship data model (mainly for database design) Object-based data models (Object-oriented and Object- relational)Semistructured data model (XML)Other older models:Network model Hierarchical model * ©Silberschatz, Korth and Sudarshan 1.* Database System Concepts - 6th Edition Relational ModelRelational model (Chapter 2)Example of tabular data in the relational model Columns Rows
  • 52. * ©Silberschatz, Korth and Sudarshan 1.* Database System Concepts - 6th Edition A Sample Relational Database * ©Silberschatz, Korth and Sudarshan 1.* Database System Concepts - 6th Edition Data Manipulation Language (DML)Language for accessing and manipulating the data organized by the appropriate data modelDML also known as query languageTwo classes of languages Procedural – user specifies what data is required and how to get those data Declarative (nonprocedural) – user specifies what data is required without specifying how to get those dataSQL is the most widely used query language * ©Silberschatz, Korth and Sudarshan 1.* Database System Concepts - 6th Edition
  • 53. Data Definition Language (DDL)Specification notation for defining the database schema Example: create table instructor ( ID char(5), name varchar(20), dept_name varchar(20), salary numeric(8,2))DDL compiler generates a set of table templates stored in a data dictionaryData dictionary contains metadata (i.e., data about data)Database schema Integrity constraintsPrimary key (ID uniquely identifies instructors)Referential integrity (references constraint in SQL) e.g. dept_name value in any instructor tuple must appear in department relationAuthorization * ©Silberschatz, Korth and Sudarshan 1.* Database System Concepts - 6th Edition SQLSQL: widely used non-procedural languageExample: Find the name of the instructor with ID 22222 select name from instructor
  • 54. where instructor.ID = ‘22222’Example: Find the ID and building of instructors in the Physics dept. select instructor.ID, department.building from instructor, department where instructor.dept_name = department.dept_name and department.dept_name = ‘Physics’ Application programs generally access databases through one ofLanguage extensions to allow embedded SQLApplication program interface (e.g., ODBC/JDBC) which allow SQL queries to be sent to a databaseChapters 3, 4 and 5 * ©Silberschatz, Korth and Sudarshan 1.* Database System Concepts - 6th Edition Database Design The process of designing the general structure of the database: Logical Design – Deciding on the database schema. Database design requires that we find a “good” collection of relation schemas.Business decision – What attributes should we record in the database?Computer Science decision – What relation schemas should we have and how should the attributes be distributed among the various relation schemas? Physical Design – Deciding on the physical layout of the database
  • 55. * ©Silberschatz, Korth and Sudarshan 1.* Database System Concepts - 6th Edition Database Design?Is there any problem with this design? * ©Silberschatz, Korth and Sudarshan 1.* Database System Concepts - 6th Edition Design ApproachesNormalization Theory (Chapter 8)Formalize what designs are bad, and test for themEntity Relationship Model (Chapter 7)Models an enterprise as a collection of entities and relationshipsEntity: a “thing” or “object” in the enterprise that is distinguishable from other objects Described by a set of attributesRelationship: an association among several entitiesRepresented diagrammatically by an entity-relationship diagram: * ©Silberschatz, Korth and Sudarshan
  • 56. 1.* Database System Concepts - 6th Edition The Entity-Relationship ModelModels an enterprise as a collection of entities and relationshipsEntity: a “thing” or “object” in the enterprise that is distinguishable from other objectsDescribed by a set of attributesRelationship: an association among several entitiesRepresented diagrammatically by an entity-relationship diagram: What happened to dept_name of instructor and student? * ©Silberschatz, Korth and Sudarshan 1.* Database System Concepts - 6th Edition Object-Relational Data ModelsRelational model: flat, “atomic” valuesObject Relational Data ModelsExtend the relational data model by including object orientation and constructs to deal with added data types.Allow attributes of tuples to have complex types, including non-atomic values such as nested relations.Preserve relational foundations, in particular the declarative access to data, while extending modeling power.Provide upward compatibility with existing relational languages. * ©Silberschatz, Korth and Sudarshan
  • 57. 1.* Database System Concepts - 6th Edition XML: Extensible Markup LanguageDefined by the WWW Consortium (W3C)Originally intended as a document markup language not a database languageThe ability to specify new tags, and to create nested tag structures made XML a great way to exchange data, not just documentsXML has become the basis for all new generation data interchange formats.A wide variety of tools is available for parsing, browsing and querying XML documents/data * ©Silberschatz, Korth and Sudarshan 1.* Database System Concepts - 6th Edition Storage ManagementStorage manager is a program module that provides the interface between the low-level data stored in the database and the application programs and queries submitted to the system.The storage manager is responsible to the following tasks: Interaction with the file manager Efficient storing, retrieving and updating of dataIssues:Storage accessFile organizationIndexing and hashing * ©Silberschatz, Korth and Sudarshan 1.*
  • 58. Database System Concepts - 6th Edition Query Processing 1. Parsing and translation 2. Optimization 3. Evaluation * ©Silberschatz, Korth and Sudarshan 1.* Database System Concepts - 6th Edition Query Processing (Cont.)Alternative ways of evaluating a given queryEquivalent expressionsDifferent algorithms for each operationCost difference between a good and a bad way of evaluating a query can be enormousNeed to estimate the cost of operationsDepends critically on statistical information about relations which the database must maintainNeed to estimate statistics for intermediate results to compute cost of complex expressions * ©Silberschatz, Korth and Sudarshan 1.* Database System Concepts - 6th Edition Transaction Management What if the system fails?What if more than one user is concurrently updating the same data?A
  • 59. transaction is a collection of operations that performs a single logical function in a database applicationTransaction- management component ensures that the database remains in a consistent (correct) state despite system failures (e.g., power failures and operating system crashes) and transaction failures.Concurrency-control manager controls the interaction among the concurrent transactions, to ensure the consistency of the database. * ©Silberschatz, Korth and Sudarshan 1.* Database System Concepts - 6th Edition Database Users and Administrators Database * ©Silberschatz, Korth and Sudarshan 1.* Database System Concepts - 6th Edition Database System Internals
  • 60. * ©Silberschatz, Korth and Sudarshan 1.* Database System Concepts - 6th Edition Database Architecture The architecture of a database systems is greatly influenced by the underlying computer system on which the database is running:CentralizedClient-serverParallel (multi- processor)Distributed * ©Silberschatz, Korth and Sudarshan 1.* Database System Concepts - 6th Edition History of Database Systems1950s and early 1960s:Data processing using magnetic tapes for storageTapes provided only sequential accessPunched cards for inputLate 1960s and 1970s:Hard disks allowed direct access to dataNetwork and hierarchical data models in widespread useTed Codd defines the relational data modelWould win the ACM Turing Award for this workIBM Research begins System R prototypeUC Berkeley begins Ingres prototypeHigh-performance (for the era) transaction processing *
  • 61. ©Silberschatz, Korth and Sudarshan 1.* Database System Concepts - 6th Edition History (cont.)1980s:Research relational prototypes evolve into commercial systemsSQL becomes industrial standardParallel and distributed database systemsObject-oriented database systems1990s:Large decision support and data-mining applicationsLarge multi-terabyte data warehousesEmergence of Web commerceEarly 2000s:XML and XQuery standardsAutomated database administrationLater 2000s:Giant data storage systemsGoogle BigTable, Yahoo PNuts, Amazon, .. * ©Silberschatz, Korth and Sudarshan 1.* Database System Concepts - 6th Edition End of Chapter 1 * ©Silberschatz, Korth and Sudarshan 1.* Database System Concepts - 6th Edition Figure 1.02
  • 62. * ©Silberschatz, Korth and Sudarshan 1.* Database System Concepts - 6th Edition Figure 1.04 * ©Silberschatz, Korth and Sudarshan 1.* Database System Concepts - 6th Edition Figure 1.06 * Database System Concepts, 6th Ed. ©Silberschatz, Korth and Sudarshan See www.db-book.com for conditions on re-use Chapter 2: Intro to Relational Model
  • 63. * ©Silberschatz, Korth and Sudarshan 2.* Database System Concepts - 6th Edition Example of a Relation attributes (or columns) tuples (or rows) * ©Silberschatz, Korth and Sudarshan 2.* Database System Concepts - 6th Edition Attribute TypesThe set of allowed values for each attribute is called the domain of the attributeAttribute values are (normally) required to be atomic; that is, indivisibleThe special value null is a member of every domainThe null value causes complications in the definition of many operations * ©Silberschatz, Korth and Sudarshan
  • 64. 2.* Database System Concepts - 6th Edition Relation Schema and InstanceA1, A2, …, An are attributes R = (A1, A2, …, An ) is a relation schema Example: instructor = (ID, name, dept_name, salary)Formally, given sets D1, D2, …. Dn a relation r is a subset of D1 x D2 x … x Dn Thus, a relation is a set of n-tuples (a1, a2, …, an) where each The current values (relation instance) of a relation are specified by a tableAn element t of r is a tuple, represented by a row in a table * ©Silberschatz, Korth and Sudarshan 2.* Database System Concepts - 6th Edition Relations are Unordered Order of tuples is irrelevant (tuples may be stored in an arbitrary order) Example: instructor relation with unordered tuples *
  • 65. ©Silberschatz, Korth and Sudarshan 2.* Database System Concepts - 6th Edition DatabaseA database consists of multiple relationsInformation about an enterprise is broken up into parts instructor student advisorBad design: univ (instructor -ID, name, dept_name, salary, student_Id, ..) results inrepetition of information (e.g., two students have the same instructor)the need for null values (e.g., represent an student with no advisor)Normalization theory (Chapter 7) deals with how to design “good” relational schemas * ©Silberschatz, Korth and Sudarshan 2.* Database System Concepts - 6th Edition sufficient to identify a unique tuple of each possible relation r(R) Example: {ID} and {ID,name} are both superkeys of instructor.Superkey K is a candidate key if K is minimal Example: {ID} is a candidate key for InstructorOne of the candidate keys is selected to be the primary key.which
  • 66. one?Foreign key constraint: Value in one relation must appear in anotherReferencing relationReferenced relation * ©Silberschatz, Korth and Sudarshan 2.* Database System Concepts - 6th Edition Schema Diagram for University Database ©Silberschatz, Korth and Sudarshan 2.* Database System Concepts - 6th Edition Relational Query LanguagesProcedural vs.non-procedural, or declarative“Pure” languages:Relational algebraTuple relational calculusDomain relational calculusRelational operators * ©Silberschatz, Korth and Sudarshan 2.* Database System Concepts - 6th Edition Selection of tuplesRelation rSelect tuples with A=B and D > 5σ A=B and D > 5 (r)
  • 67. * ©Silberschatz, Korth and Sudarshan 2.* Database System Concepts - 6th Edition Selection of Columns (Attributes)Relation r: Select A and CProjectionΠ A, C (r) * ©Silberschatz, Korth and Sudarshan 2.* Database System Concepts - 6th Edition Joining two relations – Cartesian ProductRelations r, s:r x s: * ©Silberschatz, Korth and Sudarshan 2.* Database System Concepts - 6th Edition Uni
  • 68. * ©Silberschatz, Korth and Sudarshan 2.* Database System Concepts - 6th Edition Set difference of two relationsRelations r, s:r – s: * ©Silberschatz, Korth and Sudarshan 2.* Database System Concepts - 6th Edition Set Intersection of two relationsRelation r, s: * ©Silberschatz, Korth and Sudarshan 2.* Database System Concepts - 6th Edition
  • 69. Joining two relations – Natural JoinLet r and s be relations on schemas R and S respectively. Then, the “natural join” of relations R and S is a relation on tr from r and ts from s. If tr and ts have the same value on each as the same value as tr on rt has the same value as ts on s * ©Silberschatz, Korth and Sudarshan 2.* Database System Concepts - 6th Edition Natural Join ExampleRelations r, s: Natural Joinr s * ©Silberschatz, Korth and Sudarshan 2.* Database System Concepts - 6th Edition Figure in-2.1 *
  • 70. Database System Concepts, 6th Ed. ©Silberschatz, Korth and Sudarshan See www.db-book.com for conditions on re-use End of Chapter 2 * ©Silberschatz, Korth and Sudarshan 2.* Database System Concepts - 6th Edition Figure 2.01 * ©Silberschatz, Korth and Sudarshan 2.* Database System Concepts - 6th Edition Figure 2.02 *
  • 71. ©Silberschatz, Korth and Sudarshan 2.* Database System Concepts - 6th Edition Figure 2.03 * ©Silberschatz, Korth and Sudarshan 2.* Database System Concepts - 6th Edition Figure 2.04 * ©Silberschatz, Korth and Sudarshan 2.* Database System Concepts - 6th Edition Figure 2.05 * ©Silberschatz, Korth and Sudarshan 2.* Database System Concepts - 6th Edition
  • 72. Figure 2.06 * ©Silberschatz, Korth and Sudarshan 2.* Database System Concepts - 6th Edition Figure 2.07 * ©Silberschatz, Korth and Sudarshan 2.* Database System Concepts - 6th Edition Figure 2.10 * ©Silberschatz, Korth and Sudarshan 2.* Database System Concepts - 6th Edition Figure 2.11
  • 73. * ©Silberschatz, Korth and Sudarshan 2.* Database System Concepts - 6th Edition Figure 2.12 * ©Silberschatz, Korth and Sudarshan 2.* Database System Concepts - 6th Edition Figure 2.13 * Pg. 03 Question Two Assignment #1 Deadline: Day 04/10/2019 @ 23:59
  • 74. [Total Mark for this Assignment is 5] Fundamentals of Databases IT403 College of Computing and Informatics Question One 1 Mark Learning Outcome(s): LO1 Describe fundamental data and database concepts 1. Give an example of 3 relations illustrating primary keys and foreign keys. Question Two 4 Marks Learning Outcome(s): LO7 Use Structured Query Language to perform queries and to perform relational operations.
  • 75. Consider the following relations: Student(sID, surName, firstName, campus, email) Course(dept, cNum, name) Offering(oID, dept, cNum, term, instructor) Took(sID, oID, grade) Such as: Offering[dept, cNum] ⊆ Course[dept, cNum] Took[sID] ⊆ Student[sID] Took[oID] ⊆ Offering[oID] Answer the following query using relational algebra: 1. Give the Student number of all students who have taken the course number “343” by the department “CS”. 2. Find sID of all students who have earned some grade over 80 and some grade below 50. 3. Find the Terms when the course number “369” by the department “CS” was not offered. 4. Find the Department and course number of courses that have never been offered.