0% found this document useful (0 votes)
4 views

JobPortal_Constraints_SQL

The document outlines SQL queries for managing constraints in a Job Portal Database, including creating tables, adding NOT NULL, PRIMARY KEY, UNIQUE, CHECK, and FOREIGN KEY constraints. It also includes commands for modifying existing constraints, such as enabling, disabling, and dropping them. Finally, it provides queries to view constraint definitions and associated columns for the EMPLOYEE table.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

JobPortal_Constraints_SQL

The document outlines SQL queries for managing constraints in a Job Portal Database, including creating tables, adding NOT NULL, PRIMARY KEY, UNIQUE, CHECK, and FOREIGN KEY constraints. It also includes commands for modifying existing constraints, such as enabling, disabling, and dropping them. Finally, it provides queries to view constraint definitions and associated columns for the EMPLOYEE table.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Job Portal Database - Constraints & SQL Queries

Q1) Create table EMP1 with NOT NULL for DEPTNO and PRIMARY KEY for EMPNO

CREATE TABLE emp1 (

empno NUMBER(4),

emp_name VARCHAR2(100),

emp_email VARCHAR2(100),

emp_mobile VARCHAR2(15),

emp_pass VARCHAR2(255),

emp_add VARCHAR2(255),

deptno NUMBER(7,2) NOT NULL,

CONSTRAINT emp1_pk PRIMARY KEY(empno)

);

Q2) Add NOT NULL constraint to EMPLOYEE emp_name and emp_email columns

ALTER TABLE employee MODIFY (emp_name VARCHAR2(100) NOT NULL, emp_email VARCHAR2(100)

NOT NULL);

Q3) Add PRIMARY KEY to emp_id of EMPLOYEE

ALTER TABLE employee ADD CONSTRAINT emp_pk PRIMARY KEY(emp_id);

Q4) Add PRIMARY KEY to job_id of JOB table

ALTER TABLE job ADD CONSTRAINT job_pk PRIMARY KEY(job_id);

Q5) Add UNIQUE constraint to job_name column of JOB table

ALTER TABLE job ADD CONSTRAINT job_uk UNIQUE(job_name);

Q6) Add CHECK constraint to ensure emp_id between 100 and 9999 in EMPLOYEE

ALTER TABLE employee ADD CONSTRAINT emp_ck CHECK(emp_id BETWEEN 100 AND 9999);

Q7) Add FOREIGN KEY from job_emp_id in JOB to emp_id in EMPLOYEE


Job Portal Database - Constraints & SQL Queries

ALTER TABLE job ADD CONSTRAINT job_fk FOREIGN KEY(job_emp_id) REFERENCES

employee(emp_id);

Q8) Add FOREIGN KEY to EMP1 to ensure mgr exists as empno in EMP1

ALTER TABLE emp1 ADD CONSTRAINT emp_mgr_fk FOREIGN KEY(mgr) REFERENCES emp1(empno);

Q9) Remove manager constraint from EMP1 table

ALTER TABLE emp1 DROP CONSTRAINT emp_mgr_fk;

Q10) Remove PRIMARY KEY on JOB and drop associated FK on JOB.job_emp_id

ALTER TABLE job DROP PRIMARY KEY CASCADE;

Q11) Disable the PRIMARY KEY constraint of EMPLOYEE

ALTER TABLE employee DISABLE CONSTRAINT emp_pk CASCADE;

Q12) Enable the PRIMARY KEY constraint of EMPLOYEE

ALTER TABLE employee ENABLE CONSTRAINT emp_pk;

Q13) View all constraint definitions on EMPLOYEE

SELECT constraint_name, constraint_type, search_condition

FROM user_constraints

WHERE table_name = 'EMPLOYEE';

Q14) View columns associated with constraint names on EMPLOYEE

SELECT constraint_name, column_name

FROM user_cons_columns

WHERE table_name = 'EMPLOYEE';

You might also like