Download as pdf or txt
Download as pdf or txt
You are on page 1of 2

Taller No.

3
1. Add a table-level PRIMARY KEY constraint to the EMPLOYEE table using the ID
column. The constraint should be named at creation.
Hint: The constraint is enabled as soon as the ALTER TABLE command executes
successfully.

RTA:
1. ALTER TABLE EMPLOYEE
ADD CONSTRAINT my_employee_id_pk PRIMARY KEY (id);

2. Create a PRIMARY KEY constraint on the DEPARTMENT table using the ID


column. The constraint should be named at creation.
Hint: The constraint is enabled as soon as the ALTER TABLE command executes
successfully.
RTA:
1. ALTER TABLE DEPARTMENT
ADD CONSTRAINT DEPARTMENT_ID_PK PRIMARY KEY (ID);

2. Add a foreign key reference on the EMPLOYEE table that will ensure that the
employee is not assigned to a nonexistent department.
RTA:
1. ALTER TABLE EMPLOYEE
ADD CONSTRAINT EMPLOYEE_DEPT_ID_FK FOREIGN KEY ( DEPT_ID )
REFERENCES DEPARTMENT ( ID );

3. Confirm that the constraints were added by querying USER_CONSTRAINTS. Note


the types and names of the constraints. Save your statement text in a file called
p11q4.sql.

CONSTRAINT_NAME C

DEPARTMENT_ID_PK P
EMPLOYEE_ID_PK P
EMPLOYEE_DEPT_ID_FK R

RTA
1. DESC USER_CONSTRAINT
2. Edit p11q4.sql
3. SELECT CONSTRAINT_NAME, CONSTRAINT_TYPE
FROM USER_CONSTRAINTS
WHERE TABLE_NAME IN ('EMPLOYEE', 'DEPARTMENT';
4. Save p11q4.sql
4. Display the object names and types from the USER_OBJECTS data dictionary view
for EMPLOYEE and DEPARTMENT tables. You may want to format the columns
for readability. Notice that the new tables and a new index were created.

RTA
1- DESC USER_OBJECTS
2- COLUMN OBJECT_TYPE FORMAT A30
3- COLUMN OBJECT_NAME FORMAT A30
4- SELECT OBJECT_TYPE, OBJECT_NAME
FROM USER_OBJECTS
WHERE OBJECT_NAME LIKE 'DEPARTMENT%' OR
OBJECT_NAME LIKE ' EMPLOYEE%';

5. Modify the EMPLOYEE table. Add a SALARY column of NUMBER datatype,


precision 7.
RTA
1. ALTER TABLE EMPLOYEE ADD (SALARY NUMBER( 7 ));
2. DESC EMPLOYEE

You might also like