Professional Documents
Culture Documents
Taller 3 Katheryn Rojas
Taller 3 Katheryn Rojas
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. 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 );
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%';