Lab Examples: Primary Key Constraint

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 4

SHANZAY TAHIR DB LAB 11 2019-BSE-072

LAB EXAMPLES:

Primary Key Constraint:

Not Null Constraint:

UNIQUE Constraint:

Foreign Key Constraint:


SHANZAY TAHIR DB LAB 11 2019-BSE-072

Check Constraint:

View Constraint:
SHANZAY TAHIR DB LAB 11 2019-BSE-072

LAB TASKS

1. Add a table level primary key constraint to the “Employee_Detail” table on the ID
column. The constraint should be named at creation. Name the constraint my_emp_id_pk.

2. Create a PRIMARY KEY constraint to the “DEPT_DETAIL” table using the ID


column. The constraint should be named at creation. Name the constraint my_deptid_pk.

3. Add a column DEPT_ID to the “Employee_Detail” table. Add a foreign key reference on
the “Employee_Detail” table that ensures that the employee is not assigned to a nonexistent
department. Name the constraint my_emp_dept_id_fk.
SHANZAY TAHIR DB LAB 11 2019-BSE-072

4. Conform that the constraints were added by querying the USER_CONSTRAINTS view.
Note the types and names of the constraints.

5. Display the object names and types from USER_OBJECTS data dictionary view for the
“Employee_Detail” and “Dept_Detail” tables. Notice that the new tables and a new
index were created.

6. Modify the “Employee_Detail” table. Add a COMMISION column of NUMBER data


type, precision 2, scale 2. Add a constraint to the commission column that ensures that a
commission value is greater than zero.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy