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

DATABASE APPLICATION

SUBMITTED BY:

SAIMA NAUREEN

Assignment -3
1. Add a table level PRIMARY KEY constraint to the EMP table using the EMPNO column. This table you have created in your last lab. The constraint should be enabled at creation. SQL> CREATE TABLE emp ( empname VARCHAR2(14), Empno. NUMBER(2), dept VARCHAR2(14), address VARCHAR2(13), CONSTRAINT emp_empno. _pk PRIMARY KEY (empno.));

2. Create a PRIMARY KEY constraint to the DEPT table using the DEPTNO column. The constraint should be enabled at creation. SQL> CREATE TABLE dept( deptno NUMBER (2), dname VARCHAR2 (14), loc VARCHAR2 (13), CONSTRAINT dept_deptno_pk PRIMARY KEY (deptno));

3. Add a foreign key reference on the EMP table that will ensure that the employee is not assigned to a nonexistent department. SQL> CREATE TABLE emp( empno NUMBER(4), ename VARCHAR2(10) NOT NULL, job VARCHAR2(9), deptno NUMBER(7,2) NOT NULL, CONSTRAINT emp_deptno_fk FOREIGN KEY (deptno) REFERENCES dept (deptno))

DATABASE APPLICATION

SUBMITTED BY:

SAIMA NAUREEN

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

SQL> Select constraint_name,constraint_type,search_condition From user_constraints Where table_name = emp ;

Name of constraints which are enabled: CONSTRAINT emp_empno. _pk PRIMARY KEY (empno.)); CONSTRAINT emp_deptno_fk FOREIGN KEY (deptno) REFERENCES dept (deptno)); CONSTRAINT dept_deptno_pk PRIMARY KEY (deptno));

You might also like