Docsity

Database Modifications, Relational Algebra, The Project Operator | EEL 4852C, Study notes of Deductive Database Systems

Toggle sidebar
bg1
Database Modifications
(This section is continued from previous lecture)
• INSERT – add a new row of data
• DELETE – delete a row of data
• UPDATE – modify the values of some or all attributes of a row
* Every modification leads to a new instance.
* You will have to worry about constraints (entity & referential constraints, see previous
lecture)
Relational Algebra
Query Languages
• Procedural – user specifies what mathematical or systematic procedures
to get the results that are desired (C++, Java etc.)
• Non-procedural (declarative) – does not require semantics of what is
going on and it operates through user’s point of view. (SQL)
Basic Relational Algebra Operators
Unary Binary
Select
Projection
Rename
Aggregates
Intersection
Set difference
Cartesian product
Join
Division
Inner/outer join
–
X
|X|
÷
The SELECT Operator
Notation:
p
(r
1
) = r
2
/ where p is the selection predicate.
The Process:
1. Scan the entire table
2. if p is satisfied for a given row, add that row to r
2
An Example: for employee table: e
id=’4’
(e) – Select all employees that have an id of 4
salary=30,000
(e) – Select all employees that have a salary of 30,000
pf3

Partial preview of the text

Download Database Modifications, Relational Algebra, The Project Operator | EEL 4852C and more Study notes Deductive Database Systems in PDF only on Docsity!

Database Modifications

(This section is continued from previous lecture)

  • INSERT – add a new row of data
  • DELETE – delete a row of data
  • UPDATE – modify the values of some or all attributes of a row
  • Every modification leads to a new instance.
  • You will have to worry about constraints (entity & referential constraints, see previous lecture)

Relational Algebra

Query Languages

  • Procedural – user specifies what mathematical or systematic procedures to get the results that are desired (C++, Java etc.)
  • Non-procedural (declarative) – does not require semantics of what is going on and it operates through user’s point of view. (SQL) Basic Relational Algebra Operators Unary Binary Select Projection Rename Aggregates

Intersection Set difference Cartesian product Join Division Inner/outer join

X

|X|

÷

The SELECT Operator

Notation: p(r 1 ) = r 2 / where p is the selection predicate.

The Process:

  1. Scan the entire table
  2. if p is satisfied for a given row, add that row to r 2 An Example: for employee table: e

id=’4’ (e) – Select all employees that have an id of 4

salary=30,000 (e) – Select all employees that have a salary of 30,

Another Example: that shows how selection on an actual table

A=B^D>5 (r) – Select all rows where A=B AND D>5 in table r

table r  A=B^D>5 (r)  resulting table

A B C D

Features of Selection Operator

  • Schema of r 1 and r 2 are the same since you’re only doing filtering of tuples
  • The resulting r 2 will always be  to the original table r 1
  • SELECT is commutative, meaning selections can be nested because they eventually return a table. Example: p1(p2(p3(r 1 )))
  • If you have a commutative selection, the p’s can be broken up into individual conditions. o Example: p1(p2(p3(r 1 ))) can be broken up into: p WHERE p=p 1 AND p=p 2 AND p=p 3 They are equal.

The Project Operator

Notation: (column1, column2) (r 1 ) = r 2  Selects only the specified columns from the

list, and leaves the remaining columns out of the final table. Where as SELECT, selects data rows, the project operator selects attribute columns. Example: (B,D)(r 1 ) – Selects only the B and D columns, keeps all rows Table r 1 table r 2  (B,D)(r 1 )  Features of Projection

  • Schema of final table changes (because there’s less columns)
  • Final table could be smaller than initial table because of duplicates being removed. o For example, if the above first table had two rows that were identical except their D column values were different, this projection would remove the D column, and then they’ll be identical, in which one of them will be removed for being a duplicate.
  • In other words, duplicates may arise if a column is removed that, before, established the two data rows as unique

A B C D

A B C D

A A A A

Bunch Bunch Bunch Bunch Of Of Of Of data data data data

A B C D

A A A A

Bunch Bunch Bunch Bunch Of Of Of Of data data data data

B D

A A

Bunch Bunch Of Of data data

A B C D

A A A A

Bunch Bunch Bunch Bunch Of Of Of Of data data data data