Course Name: Data Base Systems Course Code: CSE 301
Sheet No.: Seven Schedule: Wednesday
1. Define each of the following terms:
a. dynamic SQL
b. correlated subquery
c. embedded SQL
d. procedure
e. join
f. equi-join
g. self join
h. outer join
i. function
2. When is an outer join used instead of a natural join?
3. Explain the processing order of a correlated subquery.
4. What are some of the purposes for which you would use correlated
subqueries?
5. Explain the relationship between EXISTS and correlated subqueries.
6. Under what conditions can a UNION clause be used?
7. When would you consider using embedded SQL? When would you use
dynamic SQL?
8. When do you think that the CASE keyword in SQL would be useful?
Main book problems on chapter seven from prob. 7-25 to prob. 7-34, pages 331-332
1
Course Name: Data Base Systems Course Code: CSE 301
Sheet No.: Seven Schedule: Wednesday
1. Define each of the following key terms:
a. Dynamic SQL. The process of making an application capable of generating specific SQL
code on the fly, as the application is processed
b. Correlated subquery. This type of subquery is processed outside in, rather than inside out.
That is, the inner query is executed for each row in the outer query, and the inner query
depends in some way on values from the current row in the outer query. The results of the
inner query will, in turn, affect the final results of the outer query.
c. Embedded SQL. The process of including hard-coded SQL statements in a program written
in another language such as C or Java
d. Procedure. A collection of procedural and SQL statements that are assigned a unique name
within the schema and stored in the database
e. Join. The most frequently used relational operation, which brings together data from two
or more related tables into one result table
f. Equi-join. A join in which the joining condition is based on equality between values in the
common columns. It produces a table of rows composed of columns from two other tables,
where common columns appear (redundantly) in the result table.
g. Self-join. A join that requires matching rows in a table with other rows in the same table.
This is a join that joins a table with itself and often occurs with the presence of a unary
relationship in the database, such as a Supervisor or Manager of Employees within an
Employee table.
h. Outer join. A join in which rows that do not have matching values in common columns
are nevertheless included in the result table. Outer joins return all the values in one of the
tables included in the join, regardless of whether a match exists in the other table(s) or not.
i. Function. A stored subroutine that returns one value and has only input parameters
2. Using an outer join instead of a natural join:
Outer joins are often used in database maintenance to find rows that do not have matching values
in common columns. Null values appear in columns where there is no match between tables.
Another example would be a query that returns all customers—whether they have placed orders
in the last four months or not— along with the date of the most recent order placed within the last
four months. Customers who have not placed an order would be returned with a null value
under most recent order.
3. Explain the processing order of a correlated subquery:
Correlated subqueries use the result of the outer query to determine the processing of the inner
query. Thus, the inner query varies for each row referenced in the outer query.
2
4. Purposes for correlated subqueries
A typical use of a correlated subquery is related to comparing an attribute value an instance has
(such as, for example, Age) to a benchmark value that is specific to a group to which the instance
belongs (such as the Average Age within a team).
5. Relationship between EXISTS and correlated subqueries
Subqueries written using the EXISTS keyword are, in practice, correlated subqueries: they also
include a reference to the outer query in the inner query and the value the inner query produces
depends on the specific row of the outer query being processed.
6. Usage of UNION clause:
Use UNION when you want to combine the output from multiple queries together. However, each
query involved must output the same number of columns, and they must be UNION-compatible
7. Usage of Embedded vs. Dynamic SQL:
Embedded SQL To create an application where you know exactly what the SQL syntax is that you
will need to use.
Dynamic SQL Use where you need to create SQL on the fly, identifying exact parameter values,
tables, and so forth at runtime.
8. Utility of CASE keyword:
The CASE keyword would be useful in a situation where you might want to assign categories, for
example a discount level based upon sales. In this example, one could use the CASE keyword to
check the sales level and assign a discount level, such as level 1 for sales < 1000, level 2 for sales
>= 1000 and <5000, etc.
7.25
3
4
5
7.28
6
b.
c.
7
b.
8
9
10