Professional Documents
Culture Documents
1. What RDBMS objects are created with the SQL CREATE statement?
The SQL CREATE statements are used to create the following objects:
STOGROUP A storage group
DATABASE A logical collection of tables
TABLESPACE An area that stores tables
TABLE A data structure organized by a specified columns
INDEX An alternate path to table data
VIEW An alternate representation of one or more tables
SYNONYM An alternate name for local table or view
ALIAS An alternate name for a table definition which may be
local or remote, existent or nonexistent
2. What RDBMS objects are required before you can create a table?
Before you create a table, you need an existing database and tablespace.
7. What is a view?
A view is a virtual table that can represent all or part of one or more tables. A view can help
simplify data access as well as provide an additional layer of access control.
8. What is a foriegn key?
A foreign key is the key defined in one table to reference the primary key of a reference
table. This foreign key must have the same structure as the reference table's primary key.
18.When is the results table for the query in a DECLARE CURSOR statement created?
The results table for a query specified in a DECLARE CURSOR statement of
a cursor is created during the execution of the OPEN CURSOR statement.
19. How do you bring the data from the result table into your program?
Data is brought into a program's working storage area from a results table
by issuing a FETCH cursor-name statment.
21. After an SQL statement is executed, what do you infer from the SQLCODE
variable when it is:
(a) Positive : The statement did execute, but constitutes a warning
that some exception condition occurred.
(b) Negative : That an error occurred and the statement did not
complete successfully.
(c) Zero : The statement executed sucessfully.
(ci)
23. How do you code a join of two tables that share the same column name?
The columns names in the select clause need to be qualified by the table
or view name they belong to and could be coded as follows:
EXEC SQL
SELECT table1.column1, table2.column1,
table1.column2, table2.column2
FROM table1,table2
END-EXEC.
25. Where and when is the HAVING clause used and what does it do?
The HAVING clause is coded after the GROUP BY clause in a query that is
summarizing results by one or more grouping columns. The HAVING clause
behaves the same as the WHERE clause except that is is used to specify
the conditions each returned group must satisfy. If one row in the group
fails the conditions of the HAVING clause, the entire group is not
returned as part of the result.
26. When would you use the UNION keyword instead of join?
A join depends on the common values of the columns named in a search
condition. If there are no common values in two tables(for the specified
search columns), there would be no way to combine data from two tables
that did not have a common range of values. For example, if employee data
was stored in separate district tables, and the districts did not share
employees(have the same employee in more than one district), it would be
impossible to join the tables by employee id. In this situation, in order
to retrieve all of the employees from three districts, you would have to
code a UNION of the three tables as follows:
EXEC SQL
SELECT empid, empname, salary
FROM district1-tab
UNION
SELECT empid, empname, salary
FROM district2-tab
UNION
SELECT empid, empname, salary
FROM district3-tab
END-EXEC.
30. If you have two similar tables combined by the UNION keyword, how can you tell which
table a result row came from?
Place a different constant at the end of the column list in the SELECT
clause of each SELECT statement in the union. The merged result will have
this constant present to indicate which SELECT statement and therefore
from which table the row came. Look at the following example:
EXEC SQL
SELECT col1, col2, col3, 'table1'
FROM table1
UNION
SELECT col1, col2, col3, 'table2'
FROM table2
END-EXEC.
The final result rows will have a 'TABLE1' or 'TABLE2' constant to tell
you which table they came from.
34. What is the difference between cursor stability and repeatable read?
With the isolation level set to Cursor stability during read-only
processing, a page lock is held all the while an applications cursor is
positioned on it. As soon as the cursor acquires a lock on the next
required page (i.e.,the cursor is positioned on a different page of data),
the previous page lock is released.
With the isolation level set to Repeatable Read, all of the pages of data
selected by the DECLARE CURSOR statement are locked until the next
explicit or implicit commit.
41. Does COUNT function include a column which has null values?
In COUNT function nulls are handled just like non-null values.
42. Does AVG function take into account columns with NULL?
In AVG function nulls are handled just like non-null values.
43. What is a NULL INDICATOR? Why are they used? How is it defined?
If the data type is nullable, the application must provide a null
indicator. Otherwise an error may occur. If a null indicator is not used,
an SQLCODE = -305 is returned.
EXEC SQL
FETCH c1 INTO :cm
INDICATOR :cmid
END-EXEC.
If cmid < 0
DISPLAY 'commission is null'
If cmid is < 0 - the fetched value is NULL and cm should not be used.
45. How can you sort the output of a query in the order of the results of an expression in
the SELECT clause?
Use the ORDER BY clause and refer to the expression by its position in the
list of columns named in the SELECT clause. For example:
EXEC SQL
SELECT column1, column2, column3, (column1 - column3),
FROM table-a
ORDER BY 4
END-EXEC.
47. How can you work through a results table in reverse order?
You cannot. However, you can specify the sort key as descending in the
ORDER BY clause.
53. What is the minimum number of tables required to enforce referential integrity?
One.
60. What is the purpose of the WITHHOLD option in the DECLARE CURSOR?
WITHHOLD option is used to retain cursor position. Whenever a COMMIT is
issued all open cursors are automatically closed unless the WITHHOLD
option is coded for the cursor.
WITHHOLD prevents subsequent COMMITs from destroying the intermediate
results table from the SELECT statements thereby saving positioning with
the cursor.
65. In a CICS/DB2 program, would you use a CICS SYNCPOINT or a SQL COMMIT to
commit your updates to the database? Why?
67. List any two DB2 scalar functions and their use.
DATE : Converts scalar value to Date
TIME : Converts scalar value to Time
69. How many rows can be retrieved using a SELECT INTO statement in an
application?
Only one row.