0% found this document useful (0 votes)
60 views2 pages

Assignment# 03

The document describes adding constraints to database tables. It instructs to: 1) Add a primary key constraint to the EMP table on the EMPNO column. 2) Add a primary key to the DEPT table on the DEPTNO column. 3) Add a foreign key to the EMP table to reference the DEPT table and ensure employees are not assigned to nonexistent departments. 4) Query the USER_CONSTRAINTS table to confirm the constraints were added correctly.

Uploaded by

saima
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
60 views2 pages

Assignment# 03

The document describes adding constraints to database tables. It instructs to: 1) Add a primary key constraint to the EMP table on the EMPNO column. 2) Add a primary key to the DEPT table on the DEPTNO column. 3) Add a foreign key to the EMP table to reference the DEPT table and ensure employees are not assigned to nonexistent departments. 4) Query the USER_CONSTRAINTS table to confirm the constraints were added correctly.

Uploaded by

saima
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 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

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