Question 1
The EMPLOYEES table in your own schema was created exactly as shown, and no constraint has been added or dropped since: ```sql CREATE TABLE employees ( emp_id NUMBER(6) PRIMARY KEY, first_name VARCHAR2(30) NOT NULL, last_name VARCHAR2(30) NOT NULL, salary NUMBER(8, 2), commission NUMBER(4, 2), manager_id NUMBER(6), dept_id NUMBER(4), CONSTRAINT emp_dept_fk FOREIGN KEY (dept_id) REFERENCES departments (dept_id) ); ``` How many rows does the following query return? ```sql SELECT constraint_name, constraint_type FROM user_constraints WHERE table_name = 'EMPLOYEES' ```
A. 2
Treats NOT NULL as a column attribute rather than a constraint, counting only the primary key and the foreign key. Oracle implements a NOT NULL column as a check constraint, so each one is its own row with CONSTRAINT_TYPE = 'C'.
B. 3
Assumes a referential constraint is recorded under the parent table it points at, so EMP_DEPT_FK would appear under DEPARTMENTS. A type 'R' constraint is stored under the child table that declares it — the parent is identified by R_CONSTRAINT_NAME.
C. 4Correct answer
One 'P' row for the system-named primary key, one 'R' row for EMP_DEPT_FK, and one 'C' row for each of the two NOT NULL columns FIRST_NAME and LAST_NAME — four rows in all (Oracle Database Reference, ALL_CONSTRAINTS: CONSTRAINT_TYPE).
D. 5
Assumes a PRIMARY KEY also generates a separate NOT NULL check constraint for EMP_ID on top of its 'P' row. The primary key enforces mandatory values itself: the column shows NULLABLE = 'N' in USER_TAB_COLUMNS, but no extra 'C' row is created.
Explanation
USER_CONSTRAINTS holds one row per constraint defined on a table owned by the current user, and CONSTRAINT_TYPE distinguishes them: 'P' for a primary key, 'U' for unique, 'R' for referential integrity, and 'C' for a check — a category that includes every NOT NULL column, since Oracle implements NOT NULL as a system-named check constraint. A referential constraint is recorded against the child table that declares it, not the parent it references, and a primary key produces a single 'P' row rather than an additional NOT NULL check on its column.