Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

PL SQL

Download as pdf or txt
Download as pdf or txt
You are on page 1of 7

PRACTICAL-1

Ques: Create an EMP Table with the column name EID, EName, Salary, City with
data type number, varchar, number and varchar respectively, display the structure
of the table, insert the records in the table and display all the records.

COMMAND:

CREATE DATABASE OFFICE;


USE OFFICE;
CREATE TABLE EMP(EID INT ,ENAME VARCHAR(50),SALARY INT, CITY
VARCHAR(50));
INSERT INTO EMP VALUES (101,'RAM',30000,'SONIPAT');
INSERT INTO EMP VALUES (102,'SHYAM',50000,'DELHI');
INSERT INTO EMP VALUES (103,'SHRUTHI',65500,'DELHI');
INSERT INTO EMP VALUES (104,'ISHA',45500,'SONIPAT');
INSERT INTO EMP VALUES (105,'AMAN',33500,'SONIPAT');

OUTPUT:
PRACTICAL-2

Ques: Display the following :


i) All the records who are getting salary from 40,000 to 80,000

COMMAND:
SELECT * FROM EMP WHERE SALARY > 40000 AND SALARY
< 80000;

OUTPUT:

ii) EID of employee whose name starts with the letter A.

COMMAND:
SELECT EID FROM EMP WHERE ENAME LIKE'A%';

OUTPUT:
iii) Name of employee whose EID is 10,9,3,14,19

COMMAND:
SELECT ENAME FROM EMP WHERE EID IN (10,9,3,14,19);

OUTPUT:

iv) Name of employee whose EID is greater than 10 and city is Delhi.

COMMAND:
SELECT ENAME FROM EMP WHERE EID >10 AND CITY='DELHI';

OUTPUT:
v) Average and maximum salary of all employee and count the no of
employee.

COMMAND:
SELECT COUNT(*),AVG(SALARY),MAX(SALARY) FROM EMP;

OUTPUT:
PRACTICAL-3

Ques.Change the data type of EID of EMP table from Number to varchar
and add one more column EDepartment with data type varchar.

COMMANDS:

ALTER TABLE EMP MODIFY EID VARCHAR(20);

OUTPUT:

COMMANDS:

ALTER TABLE EMP ADD DEPARTMENT VARCHAR(20);

OUTPUT:
PRACTICAL-4

Create a table Department with column Dep_ID, Dep_Name and set the
referential integrity with EMP table. Dep_ID should be foreign key in EMP
table and insert some record in both the table and display department name
of those employee who belongs to City Delhi.

COMMAND:
CREATE TABLE EMP(EID INT, ENAME VARCHAR(40), SALARY INT, CITY
VARCHAR(40),DEP_ID INT);
INSERT INTO EMP VALUES (101,'AMAN',78000,'DELHI',201);
INSERT INTO EMP VALUES (102,'MOHIT',90000,'DELHI',202);
INSERT INTO EMP VALUES (103,'ROHAN',78000,'SONIPAT',203);
INSERT INTO EMP VALUES (104,'SNEHA',86500,'DELHI',204);
INSERT INTO EMP VALUES (105,'KPSC',878000,'SONIPAT',205);
CREATE TABLE DEPARTMENT ( DEP_ID INT NOT NULL , DEP_NAME
VARCHAR(5 0) NOT NULL , FOREIGN KEY (DEP_ID) REFERENCES
EMP(DEP_ID));
INSERT INTO DEPARTMENT VALUES (201,'MECHANICAL');
INSERT INTO DEPARTMENT VALUES (202,'CSE');
INSERT INTO DEPARTMENT VALUES (203,'CSE');
INSERT INTO DEPARTMENT VALUES (204,'CIVIL');
INSERT INTO DEPARTMENT VALUES (205,'CIVIL');
SELECT DEP_NAME FROM EMP WHERE CITY =’DELHI’;

OUTPUT:

You might also like