CSC 675 Review 4 - Relational Algebra and SQL Flashcards

1
Q

What is the purpose of the relational algebra select operation?

A

Restriction - The SELECT operation is used to choose a subset of the tuples from a relation that satisfies a selection condition.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is the purpose of the relation algebra project operation?

A

Selects certain columns from the table and discards the other columns.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is the purpose of the relational algebra join operation?

A

Is used to combine related tuples from two relations into single “longer” tuples.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is the purpose of the relation algebra union operation?

A

A collection of tuples is the set of all distinct elements.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is the purpose of the relational algebra difference operation?

A

Produces a relation that includes all the tuples in R1 that are not in R2; R1 and R2 must be union compatible.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is the purpose of the relation algebra intersection operation?

A

Produces a relation that includes all the tuples in both R1 and R2; R1 and R2 must be union compatible.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What is the purpose of the relational algebra division operation?

A

Division identifies the attribute values from a relation that are found to be paired with all of the values from another relation.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What is the purpose of the relational algebra cartesian product operation?

A

All ordered pairs of tuples from the two relations.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Explain how join can be expressed using the other relational operation.

A

a join can be expressed as multiple selects

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Explain how division can be expressed using the relational operation.

A

division can be expressed as multiple selects

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What is union compatibility? *

A

• Relations have the same number of
attributes
• Corresponding attributes have the same domains

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Why do the union, intersection and difference operations require that the relations on which they are applied be union compatible? *

A

Union, intersection, and difference require union compatibility because these operation require direct comparison of the individual tuples.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

what is the standard definition of a natural join?

A

Produces all the combinations of tuples from R1 and R2 that satisfy a join condition with only equality comparisons. Without the duplicate columns.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What is the standard definition of an equijoin?

A

Produces all the combinations of tuples from R1 and R2 that satisfy a join condition with only equality comparisons.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Under what circumstances are outer joins useful? *

A

We wan to use outer joins when we want to know all the information from a join. When you do an outer join all the tuples not contained within the join are completed with null values. This is the reason why outer joins are not considered part of the relational algebra. In “pure” relation algebra, there are no null values.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Why are they sometimes not considered to be part of the relational algebra?

A

?

17
Q

What is a query tree? *

A

Binary tree representation of fully parenthesized relational algebra expression
• relations correspond to leaves!
• relational operators correspond to internal
nodes
• unary operators have one child
• binary operators have two children
• Order of evaluation corresponds to a postorder traversal of the query tree, however most systems use iterators and pipelining whenever possible

18
Q

How is a query tree different from a relational algebra expression? *

A

It’s a visualization of the query.

19
Q

How are query trees used in relational query optimization and processing?

A

To visualize the query and rearrange it to be more efficeint. slide 224 ?

20
Q

You should be able to write relational algebra expressions to answer simple SPJ queries about a given collection of data.

A

?

21
Q

How do the relations (tables) in SQL differ from the relations defined formally for the relational algebra?

A

?

22
Q

Why does SQL allow duplicate tuples in a table or in a query result?

A

tables in SQL are not sets–duplicate tuples are allowed unless specifically eliminated from the result (select distinct attlist) or disallowed by a declared primary key (this does not apply to the result of queries).!

23
Q

How are primary key and foreign key constrains expressed in SQL?

A

PRIMARY KEY (P_Id)

P_Id int FOREIGN KEY REFERENCES Persons(P_Id)

24
Q

What is a view in SQL?

A

A view is a virtual relation defined as the result of any legal SQL query. The view behaves as if it is not materialized until a query against it is executed, and consequently is always up to date with respect to the underlying data values in the database

25
Q

How is it defined?

A

CREATE VIEW view_name AS
SELECT column_name(s)
FROM table_name
WHERE condition

26
Q

Why is it sometimes impossible to update a view? *

A

It is sometimes not possible to update a view when the view is over more than one table. It is never possible to update a view that has aggregates in it.

27
Q

Under what circumstances is it possible?

A

It is possible to update a view when the view is over only one table and their are not aggregates used in it.

28
Q

What is a cursor?

A

is a control structure that enables traversal over the records in a database.

29
Q

How are cursors used in embedded SQL?

A

when open command executes. All tuples are materialized and cursor placed before first tuple. Each call to fetch advances cursor to next tuple and returns those values. close releases all resources.

30
Q

You should be able to write SQL programs to answer simple SPJ queries about a given collection of data.

A

?

31
Q

You should also be able to give an equivalent relational algebra expression for SQL SPJ queries.

A

?