June 2019
June 2019
INSTRUCTIONS
[Turn over]
2 INF3707
MAY/JUNE 2019
1.1 Which of the following is true about the SQL query given below? (Choose the best answer)
Select col1, col2
From tab1
Where col1 = ‘A’
Order by col2 DESC, col1;
A. It will display the row which has the col1 value as 'A' ordered by the col1 in the descending
order and then col2 in the descending order.
B. The ORDER BY clause will not work as the keyword DESC should be always written in the
end of the ORDER BY clause and not in between as given in the query.
C. The above query will be sorted in descending order on the basis of col2 only and the use of col1
in the ORDER BY clause will be discarded.
D. It will display the row which has the col1 value as 'A' ordered by the col1 and then followed by
col2 as the execution of the ORDER BY clause happens from the order of columns in the
SELECT statement.
1.2 What does the following query do? (Choose the best answer)
Select isbn, title
from BOOKS
where (pubid, category) IN
(select pubid,category from BOOKS where title like '%ORACLE%')
A. It determines which publisher published a book belonging to the Oracle category and then lists
all other books published by that same publisher.
B. It lists all publishers and categories containing the value of ORACLE.
C. It lists the ISBN and title of all books belonging to the same category and having the same
publisher as any book with the phrase ORACLE in its title.
D. None of the above. The query contains a multiple-row operator and because the inner query
returns only one value, the SELECT statement will fail and return an error message.
1.3 Based on the structure of the CUSTOMERS table given below, which of the following is a valid
SQL statement? (Choose the best answer)
[Turn over]
3 INF3707
MAY/JUNE 2019
1.4 Which data dictionary objects contain a column named HIDDEN_COLUMN? (Choose the best
answer)
A. USER_HIDE_COLS
B. USER_TABLES
C. USER_COLUMNS
D. USER_TAB_COLS
1.5 Which of the following commands lock the JustLee database’ BOOKS table in EXCLUSIVE
mode? (Choose the best answer)
A. LOCK table BOOKS EXCLUSIVELY
B. LOCK table BOOKS IN EXCLUSIVE MODE
C. LOCK table BOOKS TO OTHER USERS
D. All the answers are correct
A. DAVID may grant this privilege to all users in the database, but he may not grant it to PUBLIC.
B. DAVID may grant this privilege to a role that has been granted to him
C. DAVID may revoke this privilege from users who have been granted this privilege by him.
D. The DBA may revoke this privilege from roles that have been granted this privilege by DAVID.
[Turn over]
4 INF3707
MAY/JUNE 2019
1.7 Which three statements are true about roles? (Choose 3 best answers that apply)
A. A password may be specified for a role only when the role is created.
B. A role may be granted both system and object privileges.
C. A role may be dropped only after it is revoked manually from all users and roles to which it has
been granted.
D. Multiple roles may be granted to a role.
E. Multiple roles granted to a user may be enabled as default roles for that user.
1.8 Which three statements are true about indexes in Oracle Database 12c? (Choose 3 best answers that
apply)
A. There may be more than one index on a single column.
B. Indexes may not always speed up data access to table data.
C. Invisible indexes are not maintained by data manipulation language (DML) operations.
D. Multiple invisible indexes may exist on a column.
E. Indexes may be created on a view.
1.9 Which of the following are valid CREATE TABLE statements? (Choose 3 best answers that apply.)
A.
CREATE TABLE $ORDERS
(ID NUMBER,NAME VARCHAR2(30));
B.
CREATE TABLE CUSTOMER_HISTORY
(ID NUMBER, NAME VARCHAR2(30));
C.
CREATE TABLE “Boat Inventory”
(ID NUMBER, NAME VARCHAR2(30));
D.
CREATE TABLE workSchedule
(ID NUMBER, NAME VARCHAR2(30));
1.10 Which of the following are Data Manipulation Language statements? (Choose 2 best answers that
apply.)
A. SELECT
B. GRANT
C. INSERT
D. DROP
1.11 Which of the following is true of the ORDER BY clause? (Choose 2 best answers that apply.)
A. It can be used in the UPDATE statement as well as SELECT and DELETE.
B. It can sort rows based on data that isn’t displayed as part of the SELECT statement.
C. If the list of ORDER BY expressions uses the “by position” form, then all expressions in the ORDER
BY must use the “by position” form.
D. It is optional.
[Turn over]
5 INF3707
MAY/JUNE 2019
2.2 Based on the tables of the JustLee books database, determine the average profit generated by the
orders in the ORDERS table. Calculate the total profit of the orders before finding the average profit.
Create the query using group functions AVG, SUM and GROUP BY. Base your query on the BOOKS,
ORDERS and ORDERITEMS tables. (10 marks)
2.3 Study the two pieces of code presented below, Code 1 and Code 2. Code 1 creates a database Table
named TEST_IDENT and code 2 inserts data into the TSET_IDENT table. What is the output after
execution Code 1 and Code 2? Explain your answer. (6 marks)
Code 1
Create table TEST_IDENT
(col1 number generated as identity primary key,col2 number);
Code 2
Insert into TEST_IDENT (col1) values (350)
Insert into TEST_IDENT (col1, col2) values (222, 355)
Insert into TEST_IDENT (col1, col2) values (Default, 360)
JustLee Books would like to create some new tables to store office equipment inventory data. The
diagram below shows a basic E-R model for the three tables including the needed columns and
relationship lines. The underlined columns uniquely identify each row in the associated tables.
After analysing the data requirements, the following list of requirements, which will be addressed with
constraints, were developed.
Each department must be unique (Dept_ID, Number (2), CONSTRAINT PRIMARY KEY)
Each department must be assigned a name (Dept_Name, varchar 2 (10))
Each equipment type must be unique (EquipType_ID, Number (2), CONSTRAINT PRIMARY
KEY)
[Turn over]
6 INF3707
MAY/JUNE 2019
3.1 Based on the information provided, write SQL statements for creating the EQUIPMENT TABLE,
the table in the middle of the E-R model. (10 marks).
3.2 Display all the constraints that exists in the EQUIPMENT table (5 marks).
3.3 Create a sequence for populating the Equip_ID column of the EQUIPMENT table. Name the
sequence Equip_Data_ID_Seq. Start the sequence at 10, increment the sequence by 2, have a
maximum value of 1000 and do not allow caching. (5 marks)
3.4 Add the data in the table below to the EQUIPMENT table. Use the Equip_Data_ID_Seq
sequence to populate the Equip_id column. (5 marks)
3.6 Drop the primary key for the EQUIPMENT table. (2 marks)
3.7 Create a private synonym that enables you to reference Equip_Data_ID_Seq object as
EQUIP_DATA. (2 marks)
3.8 Create a B-tree index on the EQUIPMENT’s Equip_desc column. Verify that the index exists
by querying the data dictionary. Remove the index from data dictionary. (5 marks)
The end
©
UNISA 2019
[Turn over]