Lesson 10: Including Constraints: SQL Sample Questions
Lesson 10: Including Constraints: SQL Sample Questions
Lesson 10: Including Constraints: SQL Sample Questions
3. Which script would you use to query the data dictionary to view only the names of the
primary key constraints using a substitution parameter for the table name?
A. SELECT constraint_name
FROM user_constraint
WHERE table_name = UPPER(‘&table’ )
AND constraint_type = ‘P’;
B. SELECT constraint_name
FROM user_constraint
WHERE table_name = UPPER (‘&table’)
AND constraint_type = ‘PRIMARY’;
C. SELECT constraint_name,constraint_type
FROM user_constraint
WHERE table_name = UPPER (‘&table’);
D. SELECT constraint_name
FROM user_cons_columns
WHERE table_name = UPPER (‘&table’)
AND constraint_type = ‘P’;
A
1
SQL Sample Questions
EMPLOYEES
MGR_I
Employee_id EMP_NAME DEPT_ID D JOB_ID SALARY
101 Smith 20 120 SA_REP 4000
102 Martin 10 105 CLERK 2500
103 Chris 20 120 IT_ADMIN 4200
104 John 30 108 HR_CLERK 2500
105 Diana 30 108 HR_MGR 5000
106 Brayan 40 110 ADD_ASST 3000
108 Jennifer 30 110 HR_DIR 650
110 Bob 40 EX_DIR 8000
120 Ravi 20 110 SA_DIR 6500
DEPARTMENTS
DEPARTMENT_ID DEPARTMENT_NAME
10 Admin
20 Education
30 IT
40 Human Resources
Also examine the SQL statements that create the EMPLOYEES and DEPARTMENTS
tables:
DELETE
FROM departments
WHERE department id = 40;
2
SQL Sample Questions
3
SQL Sample Questions
For which columns would an index be automatically created when you execute the above
SQL statement? (Choose two)
A. SER_NO
B. ORDER_ID
C. STATUS
D. PROD_ID
E. ORD_TOTAL
F. Composite index on ORDER_ID and ORDER_DATE
AF
7. For which two constraints does the Oracle Server implicitly create a unique index?
(Choose two.)
A. NOT NULL
B. PRIMARY KEY
C. FOREIGN KEY
D. CHECK
E. UNIQUE
BE
8. Examine the structure of the EMPLOYEES and NEW_EMPLOYEES tables:
EMPLOYEES
EMPLOYEE_ID NUMBER Primary Key
LAST_NAME VARCHAR2(25)
FIRST_NAME VARCHAR2(25)
HIRE_DATE DATE
NEW EMPLOYEES
A. UPDATE new_employees
SET name = (Select last_name||first_name
FROM employees
WHERE employee_id =180)
WHERE employee_id =180;
B. UPDATE new_employees
SET name = (SELECT last_name||first_name
FROM employees)
WHERE employee_id =180;
C. UPDATE new_employees
SET name = (SELECT last_name||first_name
FROM employees
WHERE employee_id=180)
WHERE employee_id =(SELECT employee_id
FROM new employees);
D. UPDATE new_employees
SET name = (SELECT last name||first_name
FROM employees
WHERE employee_id=(SELECT employee_id
FROM new_employees))
WHERE employee_id=180;
4
SQL Sample Questions
A
9. Which three statements correctly describe the functions and use of constraints? (Choose
three.)
A. UNIQUE
B. NOT NULL
C. CHECK
D. PRIMARY KEY
E. FOREIGN KEY
B
11. Examine the data in the EMPLOYEES table.
EMPLOYEES
MGR_I
Employee_id EMP_NAME DEPT_ID D JOB_ID SALARY
101 Smith 20 120 SA_REP 4000
102 Martin 10 105 CLERK 2500
103 Chris 20 120 IT_ADMIN 4200
104 John 30 108 HR_CLERK 2500
105 Diana 30 108 HR_MGR 5000
106 Brayan 40 110 ADD_ASST 3000
108 Jennifer 30 110 HR_DIR 6500
110 Bob 40 EX_DIR 8000
120 Ravi 20 110 SA_DIR 6500
Why does the DELETE statement fail when you execute it?
5
SQL Sample Questions
12. Which two statements about creating constraints are true? (Choose two)
A. Use the ALTER TABLE command with the ADD clause in the DEPT table.
B. Use the ALTER TABLE command with the ADD clause on the EMP table.
C. Use the ALTER TABLE command with the MODIFY clause on the DEPT table.
D. Use the ALTER TABLE command with the MODIFY clause on the EMP table.
E. This task cannot be accomplished.
B
14. Examine the structure of student table:
Currently the table is empty. You have decided that null values should not be allowed for
the NAME column.
Which statement restricts NULL values from being entered into column?
There are hundred records in the student table. You need to modify the Phone column to
hold only numeric value. Which statement will modify the data type of the Phone column?
6
SQL Sample Questions
D
16. In SQL Plus You issued this command:
You received an integrated constraint error because the child record was found.
A. ALTER TABLE
ENABLE PRIMARY KEY(id)
B. ALTER TABLE CARS
ENABLE CONSTRAINT cars_id_pk.
C. ALTER TABLE CARS
ENABLE PRIMARY KEY(id) CASCADE;
D. ALTER TABLE CARS
ADD CONSTRAINT cards_id_pk PRIMARY KEY(id);
B
19. You need to perform a major update on the employee table. You have decided to disable
the primary key constraint on the empid column and the check constraint on the job
column.
What happens when you try to enable the constraint after the update is completed?
A. You need to recreate the constraints once they are disabled.
B. Any existing rows that do not conform with the constraints are automatically deleted.
C. Only th future values are verified to conform with the constraints having the existing
values unchecked.
D. The indexes on both the columns with the primary key constraint and the check
constraints are automatically recreated.
E. All the existing columns values are verified to conform with the constraints and an
error message is narrated if any existing values is not conformed.
E
20. Which syntax turns an existing constraint on?
7
SQL Sample Questions
8
SQL Sample Questions
BDEG
24. Which statement adds a constraint that ensures the CUSTOMER_NAME column of the
CUSTOMERS table holds a value?
A. ALTER TABLE customers
ADD CONSTRAINT cust_name_nn CHECK customer_name IS NOT NULL;
B. ALTER TABLE customers
MODIFY CONSTRAINT cust_name_nn CHECK customer_name IS NOT NULL;
C. ALTER TABLE customers
MODIFY customer_name CONSTRAINT cust_name_nn NOT NULL;
D. ALTER TABLE customers
MODIFY customer_name CONSTRAINT cust_name_nn IS NOT NULL;
E. ALTER TABLE customers
MODIFY name CONSTRAINT cust_name_nn NOT NULL;
F. ALTER TABLE customers
ADD CONSTRAINT cust_name_nn CHECK customer_name NOT NULL;
C
25. Which view should a user query to display the columns associated with the constraints on
a table owned by the user?
A. USER_CONSTRAINTS
B. USER_OBJECTS
C. ALL_CONSTRAINTS
D. USER_CONS_COLUMNS
E. USER_COLUMNS
D
26. Which two statements are true about constraints? (Choose two.)
A. The UNIQUE constraint does not permit a null value for the column.
B. A UNIQUE index gets created for columns with PRIMARY KEY and UNIQUE
constraints.
C. The PRIMARY KEY and FOREIGN KEY constraints create a UNIQUE index.
D. The NOT NULL constraint ensures that null values are not permitted for the column.
BD
27. Which of the following integrity constraints automatically create an index when defined?
(Choose two)
A. Foreign keys
B. Unique constraints
C. NOT NULL constraints
D. Primary keys
BD
28. Which of the following dictionary views give information about the position of a column in
a primary key?
A. ALL_PRIMARY_KEYS
B. USER_CONSTRAINTS
C. ALL_IND_COLUMNS
D. ALL_TABLES
9
SQL Sample Questions
29. Which of the following choices is the strongest indicator of a parent/child relationship?
A. Two tables in the database are named VOUCHER and VOUCHER_ITEM,
respectively.
B. Two tables in the database are named EMPLOYEE and PRODUCTS, respectively.
C. Two tables in the database were created on the same day.
D. Two tables in the database contain none of the same columns.
10