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

NAME: K SAI NIROOP REDDY

EN. NO: 19STUCHH010134

Experiment No: 5
CONSTRAINTS

LAB PRACTICE ASSIGNMENT:

1. Create a table called EMP with the following structure.


Name Type
---------- ----------------------
EMPNO NUMBER (6)
ENAME VARCHAR2 (20)
JOB VARCHAR2 (10)
DEPTNO NUMBER (3)
SAL NUMBER (7,2)

Allow NULL for all columns except ename and job. (Either in Create command or
Alter Command)

Syntax: create table emp(empno int(6), ename varchar(20) NOT NULL, job varchar(10)
NOT NULL,deptno int(3), sal decimal(7,2));

2. Add constraints to check, while entering the empno value (i.e) empno > 100.

Syntax: alter table emp add constraint empno CHECK(empno>100);

3. Define the field DEPTNO as unique.

Syntax: alter table emp add unique(deptno);


NAME: K SAI NIROOP REDDY
EN. NO: 19STUCHH010134

4. Create a primary key constraint for the table(EMPNO).

Syntax: alter table emp add primary key(empno);

5. Create a default constraint and provide a salary value of "1000" if salary is not provided.

Syntax: alter table emp alter sal set default '1000';

Syntax: desc emp;

6. Create a table department with the following structure.

Name Type
---------- ----------------------
DEPTNO NUMBER (6)
DNAME VARCHAR2 (20)
LOC VARCHAR2 (10)

create a referential integrity constraint between Employee and Department table.


NAME: K SAI NIROOP REDDY
EN. NO: 19STUCHH010134
Syntax: create table department(deptno int(6), dname varchar(20), loc varchar(10), foreign
key(deptno) references emp(deptno));

Syntax: Desc department:;

Syntax: select * from department;

7.Display the Employee information along with department details.

Syntax: select * from emp,department where emp.deptno=department.deptno;

8. Display the Employee details who works in CSE department and salary less than 10000.

Syntax: Select emp.empno,emp.ename,emp.job,emp.deptno,emp.sal from emp inner join


department on emp.deptno = department.deptno where emp.sal<10000 and
department.dname="CSE";

9. Delete the Employee details who works in Hyderabad.


NAME: K SAI NIROOP REDDY
EN. NO: 19STUCHH010134
Syntax: delete emp,department from emp inner join department on
emp.deptno=department.deptno where department.loc="hyderabad";

You might also like