Oracle Final Exam Part I
Oracle Final Exam Part I
Oracle Final Exam Part I
Review your answers, feedback, and question scores below. An asterisk (*) indicates a correct answer.
Part I of the Semester 2 Final Exam covers Sections 8-9 of Database Programming with SQL.
Section 8
1. Which of the following SQL statements will create a table called Birthdays with three columns for storing employee number, name and date of birth?
CREATE table BIRTHDAYS (EMPNO, EMPNAME, BIRTHDATE); CREATE table BIRTHDAYS (employee number, name, date of birth); CREATE TABLE Birthdays (Empno NUMBER, Empname CHAR(20), Birthdate DATE); (*) CREATE TABLE Birthdays (Empno NUMBER, Empname CHAR(20), Date of Birth DATE);
Correct
Table and column names must begin with a letter. (*) Table and column names can begin with a letter or a number. Table and column names cannot include special characters. If any character other than letters or numbers is used in a table or column name, the name must be enclosed in double quotation marks.
Correct
1. CREATE TABLE customer#1 ( 2. cust_1 NUMBER(9), 3. sales$ NUMBER(9), 4. 2date DATE DEFAULT SYSDATE); Which line of this statement will cause an error?
1 2 3 4 (*)
Correct
4. You are creating the EMPLOYEES table. This table should contain the COMMISSION_PCT column and use a value of 10 percent if no commission value is provided when a record is inserted. Which line should you include in the CREATE TABLE statement to accomplish this task?
commission_pct NUMBER(4,2) DEFAULT 0.10 (*) commission_pct NUMBER(4,2) DEFAULT = 0.10 commission_pct NUMBER(4,2) DEFAULT (0.10) commission_pct NUMBER(4,2) (DEFAULT, 0.10)
Correct
CREATE TABLE date_1 (date_1 DATE); CREATE TABLE date (date_id NUMBER(9)); (*)
CREATE TABLE time (time_id NUMBER(9)); CREATE TABLE time_date (time NUMBER(9));
Correct
Correct
7. You are designing a table for the Human Resources department. This table must include a column that contains each employee's hire date. Which data type should you specify for this column?
Correct
Correct
9. You need to store the HIRE_DATE value with a time zone displacement value and allow data to be returned in the user's local session time zone. Which data type should you use?
DATETIME TIMESTAMP TIMESTAMP WITH TIME ZONE TIMESTAMP WITH LOCAL TIME ZONE (*)
Correct
How many digits to the right of the decimal point are allowed for the ELEMENTS column?
Zero Two Four (*) Six
Correct
Part I of the Semester 2 Final Exam covers Sections 8-9 of Database Programming with SQL.
Section 8
The BFILE data type stores character data up to four gigabytes in the database. The TIMESTAMP data type is a character data type. The VARCHAR2 data type should be used for fixed-length character data. The CHAR data type requires that a minimum size be specified when defining a column of this type. (*)
Correct
12. You are designing a table for the Sales department. You need to include a column that contains each sales total. Which data type should you specify for this column?
Correct
(sales_id NUMBER, customer_id NUMBER, employee_id NUMBER, sale_date TIMESTAMP WITH LOCAL TIME ZONE, sale_amount NUMBER(7,2));
(1) Points
Correct
14. You need to truncate the EMPLOYEES table. The EMPLOYEES table is not in your schema. Which privilege must you have to truncate the table?
The DROP ANY TABLE system privilege (*) The TRUNCATE ANY TABLE system privilege The CREATE ANY TABLE system privilege The ALTER ANY TABLE system privilege
Correct
15. Which command could you use to quickly remove all data from the rows in a table without deleting the table itself?
Correct
16. Your supervisor has asked you to modify the AMOUNT column in the ORDERS table. He wants the column to be configured to accept a default value of 250. The table constains data that you need to keep. Which statement should you issue to accomplish this task?
ALTER TABLE orders CHANGE DATATYPE amount TO DEFAULT 250; ALTER TABLE orders MODIFY (amount DEFAULT 250);
(*)
DROP TABLE orders; CREATE TABLE orders (orderno varchar2(5) CONSTRAINT pk_orders_01 PRIMARY KEY, customerid varchar2(5) REFERENCES customers (customerid), orderdate date, amount DEFAULT 250); DELETE TABLE orders; CREATE TABLE orders (orderno varchar2(5) CONSTRAINT pk_orders_01 PRIMARY KEY, customerid varchar2(5) REFERENCES customers (customerid), orderdate date, amount DEFAULT 250)
Correct
17. Comments on tables and columns can be stored for documentation by:
Embedding /* comment */ within the definition of the table. Using the ALTER TABLE CREATE COMMENT syntax Using the COMMENT ON TABLE or COMMENT on COLUMN (*)
Correct
18. The previous administrator created a table named CONTACTS, which contains outdated data. You want to remove the table and its data from the database. Which statement should you issue?
Correct
19. You need to remove all the rows from the SALES_HIST table. You want to release the storage space, but do not want to remove the table structure. Which statement should you use?
The DROP TABLE statement The ALTER TABLE statement The DELETE statement The TRUNCATE TABLE statement (*)
Correct
EMPLOYEE_ID NUMBER(9) Primary Key LAST_NAME VARCHAR2 (20) FIRST_NAME VARCHAR2 (20) DEPARTMENT_ID NUMBER(9) SALARY NUMBER(8,2)
Which statement will permanently remove all the data in the EMPLOYEES table, but will retain the table's structure and storage space?
DROP TABLE employees; DELETE employees; COMMIT; (*) TRUNCATE TABLE employees; ALTER TABLE employees SET UNUSED (employee_id, last_name, first_name, department_id, salary);
Correct
Part I of the Semester 2 Final Exam covers Sections 8-9 of Database Programming with SQL. Section 8 21. Which statement about a column is NOT true? You can increase the width of a CHAR column. You can modify the data type of a column if the column contains non-null data. (*) You can convert a CHAR data type column to the VARCHAR2 data type. You can convert a DATE date type column to a VARCHAR2 column. Correct 22. You want to issue the following command on a database that includes your company's inventory information: ALTER TABLE products SET UNUSED COLUMN color; What will be the result of issuing this command? The column named COLOR in the table named PRODUCTS will be assigned default values. The column named COLOR in the table named PRODUCTS will be created. The column named COLOR in the table named PRODUCTS will be deleted. The column named COLOR in the table named PRODUCTS will not be returned in subsequent reads of the table by Mark for Review (1) Points Mark for Review (1) Points
Oracle, as is has been deleted logically. (*) Correct 23. You need to remove all the data in the SCHEDULE table, the structure of the table, and the indexes associated with the table. Which statement should you use? DROP TABLE (*) TRUNCATE TABLE ALTER TABLE DELETE TABLE Correct 24. Evaluate the structure of the EMPLOYEES table: EMPLOYEE_ID NUMBER(9) LAST_NAME VARCHAR2(25) FIRST_NAME VARCHAR2(25) DEPARTMENT_ID NUMBER(9) MANAGER_ID NUMBER(9) SALARY NUMBER(7,2) The EMPLOYEE_ID column currently contains 500 employee identification numbers. Business requirements have changed and you need to allow users to include text characters in the identification values. Which statement should you use to change this column's data type? ALTER TABLE employees MODIFY (employee_id VARCHAR2(9)); ALTER TABLE employees REPLACE (employee_id VARCHAR2(9)); ALTER employees TABLE MODIFY COLUMN (employee_id VARCHAR2(15)); You CANNOT modify the data type of the EMPLOYEE_ID column, as the table is not empty. (*) Correct Section 9 25. When creating the EMPLOYEES table, which clause could you use to ensure that salary values are 1000.00 or more? CONSTRAINT CHECK salary > 1000 CHECK CONSTRAINT (salary > 1000) CONSTRAINT employee_salary_min CHECK salary > 1000 CONSTRAINT employee_salary_min CHECK (salary >= 1000) (*) Mark for Review (1) Points Mark for Review (1) Points Mark for Review (1) Points
CHECK CONSTRAINT employee_salary_min (salary > 1000) Correct 26. You need to create the PROJECT_HIST table. The table must meet these requirements: 1. The table must contain the EMPLOYEE_ID and TASKED_HOURS columns for numeric data. 2. The table must contain the START_DATE and END_DATE column for date values. 3. The table must contain the HOURLY_RATE and PROJECT_COST columns for numeric data with precision and scale of 5,2 and 10,2 respectively. 4. The table must have a composite primary key on the EMPLOYEE_ID and START_DATE columns. Evaluate this CREATE TABLE statement: CREATE TABLE project_hist ( employee_id NUMBER, start_date DATE, end_date DATE, tasked_hours NUMBER, hourly_rate NUMBER(5,2), project_cost NUMBER(10,2), CONSTRAINT project_hist_pk PRIMARY KEY(employee_id, start_date)); How many of the requirements does the CREATE TABLE statement satisfy? None of the four requirements All four of the requirements (*) Only three of the requirements Only two of the requirements Correct 27. Which type of constraint by default requires that a column be both unique and not null? FOREIGN KEY PRIMARY KEY (*) UNIQUE CHECK Incorrect. Refer to Section 9 28. Which of the following FOREIGN KEY Constraint keywords identifies the table and column in the parent table? Mark for Review Mark for Review (1) Points Mark for Review (1) Points
(1) Points RESEMBLES ON DELETE CASCADE REFERENTIAL REFERENCES (*) Correct 29. What must exist on the Parent table before Oracle will allow you to create a FOREIGN KEY constraint from a Child table? A FOREIGN KEY constraint allows the constrained column to contain values that exist in the primary key column of the parent table. A PRIMARY or UNIQUE KEY constraint must exist on the Parent table. (*) An index must exist on the Parent table. A CHECK constraint must exist on the Parent table. Correct 30. Which clause could you use to ensure that cost values are greater than 1.00? CONSTRAINT CHECK cost > 1.00 CONSTRAINT part_cost_ck CHECK (cost > 1.00) (*) CHECK CONSTRAINT part_cost_ck (cost > 1.00) CONSTRAINT CHECK part_cost_ck (cost > 1.00) Correct Mark for Review (1) Points Mark for Review (1) Points
Part I of the Semester 2 Final Exam covers Sections 8-9 of Database Programming with SQL.
Section 9
CHECK
Correct
32. Which of the following best describes the function of a CHECK constraint?
A CHECK constraint enforces referential data integrity. A CHECK constraint defines restrictions on the values that can be entered in a column or combination of columns. (*) A CHECK constraint enforces uniqueness of the values that can be entered in a column or combination of columns. A CHECK constraint is created automatically when a PRIMARY KEY constraint is created.
Correct
DONATIONS PLEDGE_ID NUMBER NOT NULL, Primary Key DONOR_ID NUMBER Foreign key to DONOR_ID column of DONORS table PLEDGE_DT DATE AMOUNT_PLEDGED NUMBER (7,2) AMOUNT_PAID NUMBER (7,2) PAYMENT_DT DATE Which CREATE TABLE statement should you use to create the DONATIONS table?
CREATE TABLE donations (pledge_id NUMBER PRIMARY KEY, donor_id NUMBER FOREIGN KEY REFERENCES donors(donor_id), pledge_date DATE, amount_pledged NUMBER,
amount_paid NUMBER, payment_dt DATE); CREATE TABLE donations (pledge_id NUMBER PRIMARY KEY NOT NULL, donor_id NUMBER FOREIGN KEY donors(donor_id), pledge_date DATE, amount_pledged NUMBER(7,2), amount_paid NUMBER(7,2), payment_dt DATE); CREATE TABLE donations pledge_id NUMBER PRIMARY KEY, donor_id NUMBER FOREIGN KEY donor_id_fk REFERENCES donors(donor_id), pledge_date DATE, amount_pledged NUMBER(7,2), amount_paid NUMBER(7,2), payment_dt DATE; CREATE TABLE donations (pledge_id NUMBER PRIMARY KEY, donor_id NUMBER CONSTRAINT donor_id_fk REFERENCES donors(donor_id), pledge_date DATE, amount_pledged NUMBER(7,2), amount_paid NUMBER(7,2), payment_dt DATE);
(*)
Correct
34. You need to add a NOT NULL constraint to the EMAIL column in the EMPLOYEES table. Which clause should you use?
Correct
35. You can view the columns used in a constraint defined for a specific table by looking at which data dictionary table?
Correct
36. You successfully create a table named SALARY in your company's database. Now, you want to establish a parent/child relationship between the EMPLOYEES table and the SALARY table by adding a FOREIGN KEY constraint to the SALARY table that references its matching column in the EMPLOYEES table. You have not added any data to the SALARY table. Which of the following statements should you issue?
ALTER TABLE salary ADD CONSTRAINT fk_employee_id_01 FOREIGN KEY (employee_id) REFERENCES employees (employee_id);
(*)
ALTER TABLE salary ADD CONSTRAINT fk_employee_id_ FOREIGN KEY BETWEEN salary (employee_id) AND employees (employee_id); ALTER TABLE salary FOREIGN KEY CONSTRAINT fk_employee_id_ REFERENCES employees (employee_id); ALTER TABLE salary ADD CONSTRAINT fk_employee_id_ FOREIGN KEY salary (employee_id) = employees (employee_id);
Correct
37. What is the syntax for removing a PRIMARY KEY constraint and all its dependent constraints?
(*)
ALTER TABLE table_name DROP CONSTRAINT FOREIGN KEY CASCADE; DROP CONSTRAINT table_name (constraint_name); ALTER TABLE table_name DROP CONSTRAINT constraint_name;
Correct
38. The DEPARTMENTS table contains these columns: DEPARTMENT_ID NUMBER, Primary Key DEPARTMENT_ABBR VARCHAR2(4) DEPARTMENT_NAME VARCHAR2(30) MANAGER_ID NUMBER
The EMPLOYEES table contains these columns: EMPLOYEE_ID NUMBER LAST_NAME VARCHAR2(25) FIRST_NAME VARCHAR2(25) DEPARTMENT_ID NUMBER JOB_ID NUMBER MANAGER_ID NUMBER SALARY NUMBER(9,2) HIRE_DATE DATE Evaluate this statement: ALTER TABLE employees ADD CONSTRAINT REFERENTIAL (manager_id) TO departments(manager_id); Which statement is true?
The ALTER TABLE statement creates a referential constraint from the EMPLOYEES table to the DEPARTMENTS table.
The ALTER TABLE statement creates a referential constraint from the DEPARTMENTS table to the EMPLOYEES table. The ALTER TABLE statement fails because the ADD CONSTRAINT clause contains a syntax error. (*) The ALTER TABLE statement succeeds, but does NOT recreate a referential constraint.
Correct
39. You need to add a PRIMARY KEY constraint on the EMP_ID column of the EMPLOYEES table. Which ALTER TABLE statement should you use?
(*)
ALTER TABLE ADD CONSTRAINT emp_emp_id_pk PRIMARY KEY employees(emp_id); ALTER TABLE employees MODIFY emp_id PRIMARY KEY; ALTER TABLE employees MODIFY CONSTRAINT PRIMARY KEY (emp_id);
LINE_ITEM_ID NUMBER PRIMARY KEY PRODUCT_ID NUMBER(9) FOREIGN KEY references the ID column of the PRODUCT table QUANTITY NUMBER(9) UNIT_PRICE NUMBER(5,2) You need to disable the FOREIGN KEY constraint. Which statement should you use?
ALTER TABLE line_item DISABLE CONSTRAINT product_id_fk; (*)
ALTER TABLE line_item DROP CONSTRAINT product_id_fk; ALTER TABLE line_item ENABLE CONSTRAINT product_id_fk; ALTER TABLE line_item DELETE CONSTRAINT product_id_fk;
Correct
Part I of the Semester 2 Final Exam covers Sections 8-9 of Database Programming with SQL.
Section 9
41. Which statement should you use to add a FOREIGN KEY constraint to the DEPARTMENT_ID column in the EMPLOYEES table to refer to the DEPARTMENT_ID column in the DEPARTMENTS table?
ALTER TABLE employees MODIFY COLUMN dept_id_fk FOREIGN KEY (department_id) REFERENCES departments(department_id); ALTER TABLE employees ADD CONSTRAINT dept_id_fk FOREIGN KEY (department_id) REFERENCES departments(department_id);
(*)
ALTER TABLE employees ADD FOREIGN KEY CONSTRAINT dept_id_fk ON (department_id) REFERENCES departments(department_id); ALTER TABLE employees ADD FOREIGN KEY departments(department_id) REFERENCES (department_id);
Correct
42. You need to add a PRIMARY KEY to the DEPARTMENTS table. Which statement should you use?
(1) Points
ALTER TABLE departments ADD PRIMARY KEY dept_id_pk (dept_id); ALTER TABLE departments ADD CONSTRAINT dept_id_pk PK (dept_id); ALTER TABLE departments ADD CONSTRAINT dept_id_pk PRIMARY KEY (dept_id); (*) ALTER TABLE departments ADD CONSTRAINT PRIMARY KEY dept_id_pk (dept_id);
Correct
43. You want to disable the FOREIGN KEY constraint that is defined in the EMPLOYEES table on the DEPARTMENT_ID column. The constraint is referenced by the name FK_DEPT_ID_01. Which statement should you issue?
ALTER TABLE employees DISABLE 'fk_dept_id_01'; ALTER TABLE employees DISABLE CONSTRAINT 'fk_dept_id_01'; ALTER TABLE employees DISABLE fk_dept_id_01; ALTER TABLE employees DISABLE CONSTRAINT fk_dept_id_01; (*)
Correct
44. What is the highest number of NOT NULL constraints you can have on a table?
5 10 3 You can have as many NOT NULL constraints as you have columns in
Correct
45. Which two statements about NOT NULL constraints are true? (Choose two)
The Oracle Server creates a name for an unnamed NOT NULL constraint. (*) A NOT NULL constraint can be defined at either the table or column level. The NOT NULL constraint requires that every value in a column be unique. Columns without the NOT NULL constraint can contain null values by default. You CANNOT add a NOT NULL constraint to an existing column using the ALTER TABLE ADD CONSTRAINT statement. (*)
Correct
46. You need to add a NOT NULL constraint to the COST column in the PART table. Which statement should you use to complete this task?
ALTER TABLE part MODIFY (cost part_cost_nn NOT NULL); ALTER TABLE part MODIFY (cost CONSTRAINT part_cost_nn NOT NULL);
(*)
ALTER TABLE part MODIFY COLUMN (cost part_cost_nn NOT NULL); ALTER TABLE part
Correct
47. You need to ensure that each value in the SEAT_ID column is unique or null. Which constraint should you define on the SEAT_ID column?
Correct
48. Primary Key, Foreign Key, Unique Key and Check Constraints can be added at which two levels? (Choose two)
Correct
49. You need to ensure that the LAST_NAME column only contains certain character values. No numbers or special characters are allowed. Which type of constraint should you define on the LAST_NAME column?
Correct
A single column can have only one constraint applied. PRIMARY KEY constraints can only be specified at the column level. NOT NULL constraints can only be specified at the column level. (*) UNIQUE constraints are identical to PRIMARY KEY constraints.
Correct