Docsity

Techniques for Manipulating Relational Data - Data Base Management System - Lecture Slides, Slides of Database Management Systems (DBMS)

Partial preview of the text

Download Techniques for Manipulating Relational Data - Data Base Management System - Lecture Slides and more Slides Database Management Systems (DBMS) in PDF only on Docsity!

Techniques for Manipulating

Relational Data

Definition Terms

• DDL (data definition language) - of a

relational system is used to define the

database’s attributes, tables, relationships,

and indexes.

• DML (data manipulation language) – is

used to extract, insert, and modify the

information content of the database.

Requiring a Formal Model

• We need a formal model that is sufficiently

powerful to allow optimization of queries.

• Relational algebra is that formal model!

What does relational algebra

operators do?

  • Reduce the number of tuples in a set by

selecting those that satisfy some criteria

(selection operators).

  • Reduce the size of each tuple in a set by

eliminating specific attributes (projection

operators).

  • Manipulate two similar sets of tuples by

combining or comparing (set operators).

  • Increase the size of each tuple by adding

attributes (join and product operations).

Using selection operator to solve

the previous task

  • Relational algebra expression would be

σlastName=‘DOE’ (Customer)

  • The new relation results from a selection

that has the same attributes as the input

relation, but may have fewer rows.

Result of finding all customers

whose last name is “Doe”

account Id firstName lastName street city state zipcode balance

111 Jane Doe 123 M St. Apopka FL 34331 0

444 Jane Doe D rm 142 Tallahassee FL 32306 10.

Using selection operator to solve

previous task

  • Relational algebra expression would be

σssn=‘376-77-0099’ and date > ’01-mar-1999’ (TimeCard)

  • The new relation results from a selection

that has the same attributes as the input

relation, but may have fewer rows.

Result of finding all employees whose ssn is 376-

77-0099 and who were employed after march 1,

ssn date startTime endTime storeId paid

376-77-0099 2/23/1999 14:00 22:00 5 yes

376-77-0099 1/3/1999 10:00 14:00 5 yes

376-77-0099 1/3/1999 15:00 19:00 5 yes

Using Projection Operator to Solve

Previous Task

  • Relational algebra expression would be

π lastName, firstName (Customer)

  • The equivalent SQL expression would be

select lastName, firstName from Customer

Result of listing the first and last

names of all customers

lastName firstName

Morehouse Anita

Block Jane

Breaux Carroll

Hamilton Cherry

Harrison Catherine

Doe Jane

Greaves Joseph

Explanation of Set Operators

• The union of two relations is a relation that

contains the set of each tuple that is in at

least one of the input relations.

• The intersection of two relations is the set

of all tuples that occur in both input

relations.

• The difference between two relations is

the set of all tuples that are in the first

relation but not in the second.

Set Operator Examples

Employee x TimeCard

Employee
ssn lastName firstName
145-09-0967 Uno Jane
245-11-4554 Toulouse Jennifer
376-77-0099 Threat Ayisha
479-98-0098 Fortune Bruce
588-99-0093 Fivozinsky Bruce
TimeCard
ssn date startTime endTime storeId paid
145-09-0967 1/14/1999 8:15 12:00 3 yes
245-11-4554 1/14/1999 8:15 12:00 3 yes
376-77-0099 2/23/1999 14:00 22:00 5 yes
145-09-0967 1/16/1999 8:15 12:00 3 yes
376-77-0099 1/3/1999 10:00 14:00 5 yes
376-77-0099 1/3/1999 15:00 19:00 5 yes

Partial Result of

σEmployee.ssn=TimeCard.ssn (Employee X TimeCard)

Employee. ssn lastName

firstNa me

TimeCard. ssn date

startTim e

endTim e storeId paid

0967 Uno Jane

0967 1/14/1999 8:15 12:00 3 no

4554 Toulouse Jie

4554 1/14/1999 8:15 12:00 3 no

0967 Uno Jane

0099 2/23/1999 14:00 22:00 5 no

4554 Toulouse Jie

0967 1/14/1999 8:15 12:00 3 no