Download unit18assignment

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts

Microsoft Access wikipedia , lookup

DBase wikipedia , lookup

Microsoft Jet Database Engine wikipedia , lookup

Database wikipedia , lookup

Extensible Storage Engine wikipedia , lookup

Functional Database Model wikipedia , lookup

Open Database Connectivity wikipedia , lookup

Ingres (database) wikipedia , lookup

Clusterpoint wikipedia , lookup

Microsoft SQL Server wikipedia , lookup

Entity–attribute–value model wikipedia , lookup

PL/SQL wikipedia , lookup

SQL wikipedia , lookup

Join (SQL) wikipedia , lookup

Relational algebra wikipedia , lookup

Database model wikipedia , lookup

Relational model wikipedia , lookup

Transcript
1
SQL Unit 16, Chapter 9 from Watson, Assignment
1. The author gives 12 requirements for a database management system to be fully
relational (not to be confused with relationally complete). What are they?
2. SQL is known as a relationally complete language. What does this mean in terms of
relational algebra? A complete answer will include a list of the five basic, or primitive
relational algebra operations.
3. What is the name of the relational algebra operation for finding matches between
corresponding attributes of two relations?
4. Is the join operation one of the basic, or primitive relational algebra operators?
5. One of the simple mistakes a person can make when writing a query that selects data
from two tables is forgetting to put an equality or inequality condition on the
corresponding fields of the two tables. What is the algebraic name for the results of the
query in this case?
6. Suppose two tables each have a field on the same domain. In order to be on the same
domain they have to meet both a syntactic and a semantic requirement. State both of
these requirements.
A)
B)
7. A general relational query is called a select, project, join (SPJ) query. Explain the
meaning of the terms select and project in this expression.
A)
B)
2
8. Which aspect of a relation is changeable, the number of tuples or the number of
attributes?
9. Modeling and normalization result in a logical model. Implementation depends on a
physical model, whether implicit or explicit. If a database system is fully relational, what
effect do changes in the physical model have on the logical model?
10. Let the two tables shown below be given. They contain only the key fields, xid and
yid. No other fields are needed for the purposes of the question. Assume that xid and yid
are of the same type and size. Write an SQL query that will find the intersection of the
two tables.
TableX(xid), TableY(yid)
11. Two table schemas are shown, followed by two queries. Assume that the queries are
executed in order, so that the second query can make use of the results of the first. Write
a single SQL query that would give a result table with the same contents. Your query
doesn't have to name the result table and it doesn't have to rename the attributes, just
generate the same data in the results.
TableX(xid, xone, xtwo)
TableY(yid, yone, ytwo)
1)
SELECT xid AS zone, xone AS ztwo, xtwo AS zthree, yid AS zfour, yone AS zfive,
ytwo AS zsix INTO TableZ
FROM TableX, TableY
2)
SELECT *
FROM TableZ
WHERE ztwo = zfour
12. Which of the following statements do you believe to be true? A) There was a day
when software vendors would supply database management systems and call them
relational even though they did not conform to all 12 requirements for a fully relational
system. Happily, these days are part of a barbaric, dimly remembered, and best-forgotten
past. B) Ignorance and sloth among users, and fraud and greed among vendors are
eternal, and the same abusive/codependent software practices of a wicked past are still
with us now, and always will be.
3
Let these three tables be given for the following four questions:
TableX
attribute: xid attribute: xone
a
g
b
h
c
i
d
i
TableY
attribute: xid attribute: zid
a
r
a
s
a
t
b
r
b
s
c
r
d
r
d
s
d
t
TableZ
attribute: zid attribute: zone
r
l
s
m
t
n
13. Notice that the table in the middle isn't a complete Cartesian product of xid and zid,
but it is like a subset of a Cartesian product for the xid values a and d. Find the table that
would result from dividing TableY by TableZ on the fields TableY.zid and TableZ.zid,
respectively. Your results will be a one column table (TableQ) which contains values
from TableY.xid.
14. Suppose some TableR was the full Cartesian product of TableX.xid and TableZ.zid.
Show the one column table (TableS) that would result from dividing TableR by TableZ
on the fields TableR.zid and TableZ.zid, respectively.
4
15. Relational division is by nature a binary operation. Using SQL syntax, relational
division can be accomplished with double NOT EXISTS. It turns out that double NOT
EXISTS on three different tables is easier to keep track of than double NOT EXISTS on
two tables, where one table appears once and the other table appears twice in the query.
That is why three tables were given for the purposes of these questions. Write the SQL
query that will find those TableX.xid values that are paired with all of the existing
TableZ.zid values. In other words, find those TableX.xid values where there does not
exist a TableZ.zid value that it's not matched with. This can be accomplished with a
double NOT EXISTS. Note that if this query is written correctly, the set of TableX.xid
values its results would contain will equal the set of TableY.xid values that would result
from dividing TableY by TableZ on the fields TableY.zid and TableZ.zid, respectively.
16. If you want to torture yourself, you can try to write the double NOT EXISTS query
which uses only TableY and TableZ in order to find the results of TableY divided by
TableZ.