You are on page 1of 16

Database Management System

BBA(GEN)2

Creating table
Employee table
Syntax :
SQL> create table employee(employeeid number(10) primarykey, employeename varchar2(15),street varchar(15),city varchar(15));

Output:
table created

Syntax:
SQL> desc employee;

Output :
Name Employeeid Employeename Street City Null? not null Type number(10) varchar2(15) varchar(15) varchar(15)

ARIHANT SIPANI

03713401711

Database Management System

BBA(GEN)2

Company table

Syntax:
SQL> create table company(companyid number(10) primarykey, companyname varchar2(50),city varchar(15));

Output:
table created

Syntax:
SQL> desc company

Output:
Name companyid companyname City Null? not null Type number(10) varchar2(50) varchar(15)

ARIHANT SIPANI

03713401711

Database Management System

BBA(GEN)2

Works table
Syntax:
SQL> create table works(employeeid number(10),companyid number(10),salary number(10),foreignkey (employeeid) reference employee, foreignkey (companyid) reference company);

Output:
Table created

Syntax:
Desc works;

Output:
Name Employeeid Companyid Salary Null? not null not null Type number(10) number(10) number(10)

ARIHANT SIPANI

03713401711

Database Management System

BBA(GEN)2

Manages table
Syntax:
SQl> create table manages(employeeid number(10), managerid number(10), foreignkey (employeeid) reference employee);

Output:

Table created

Syntax:
Desc manages

Output:
Name Employeeid managerid Null? not null Type number(10) number(10)

ARIHANT SIPANI

03713401711

Database Management System

BBA(GEN)2

INSERTING INTO THE TABLES


Employee table
Inserting 10 rows in employee table

Syntax: SQL> Insert into employee (employeeid,employeename,street,city)


values(001,suyush,firozpur,punjab);

Output: 1 row created

Syntax: SQL> Insert into employee (employeeid,employeename,street,city)


values(002,sid,shahdara,delhi);

Output: 1 row created

Syntax: SQL>Insert into employee (employeeid,employeename,street,city)


values(003,dipanshu,rajindernagar,mumbai);

Output: 1 row created

Syntax: SQL>Insert into employee (employeeid,employeename,street,city)


values(004,vicky,andheri,mumbai);

Output: 1 row created

Syntax: SQL> Insert into employee (employeeid,employeename,street,city)


values(005,bhanu,geetacolony,delhi);

Output: 1 row created

Syntax: SQL>Insert into employee (employeeid,employeename,street,city)


values(006,prashant,krishnanagar,kolkata);

Output: 1 row created

Syntax: SQL> Insert into employee (employeeid,employeename,street,city)


values(007,keshav,jhilmil,mumbai);

Output: 1 row created

ARIHANT SIPANI

03713401711

Database Management System

BBA(GEN)2

Syntax: SQL> Insert into employee (employeeid,employeename,street,city)


values(008,pooja,anandvihar,delhi);

Output: 1 row created

Syntax: SQL>Insert into employee (employeeid,employeename,street,city)


values(009,sneha,kkd,punjab);

Output: 1 row created

Syntax: SQL> Insert into employee (employeeid,employeename,street,city)


values(010,arihant,laxminagar,delhi);

Output: 1 row created

Company table
Inserting 5 rows in company table

Syntax: SQL>Insert into company (companyid,companyname,city)


values(201,firstbankcorporation,punjab);

Output: 1 row created

Syntax: SQL> Insert into company (companyid,companyname,city)


values(202,firstbankcorporation,delhi);

Output: 1 row created

Syntax: SQL> Insert into company (companyid,companyname,city)


values(203,orientalbank,mumbai);

Output: 1 row created

Syntax: SQL>Insert into company (companyid,companyname,city) values(204,orientalbank,delhi);


Output: 1 row created

Syntax: SQL> Insert into company (companyid,companyname,city)


values(205,firstbankcorporation,kolkata);

Output: 1 row created


ARIHANT SIPANI 03713401711

Database Management System

BBA(GEN)2

Works
Inserting appropriate rows in works table

Syntax: SQL> Insert into works (employeeid,companyid,salary) values(001,201,10000);


Output: 1 row created

Syntax: SQL> Insert into works (employeeid,companyid,salary) values(002,203,15000);


Output: 1 row created

Syntax: SQL> Insert into works (employeeid,companyid,salary) values(003,204,9000);


Output: 1 row created

Syntax: SQL> Insert into works (employeeid,companyid,salary) values(004,205,8000);


Output: 1 row created

Syntax: SQL>Insert into works (employeeid,companyid,salary) values(005,202,12000);


Output: 1 row created

Syntax: SQL>Insert into works (employeeid,companyid,salary) values(006,201,14000);


Output: 1 row created

Syntax: SQL> Insert into works (employeeid,companyid,salary) values(007,203,11000);


Output: 1 row created

Syntax: SQL>Insert into works (employeeid,companyid,salary) values(008,204,9500);


Output: 1 row created

Syntax: SQL> Insert into works (employeeid,companyid,salary) values(009,205,8000);


Output: 1 row created

Syntax: SQL> Insert into works (employeeid,companyid,salary) values(010,202,6500);


Output: 1 row created

ARIHANT SIPANI

03713401711

Database Management System

BBA(GEN)2

Manages table
Inserting appropriate rows in manages table

Syntax: SQL>Insert into manages(employeeid,managerid) values(001,1001);


Output: 1 row created

Syntax: SQL>nsert into manages(employeeid,managerid) values(002,1002);


Output: 1 row created

Syntax: SQL>Insert into manages(employeeid,managerid) values(003,1001);


Output: 1 row created

Syntax: SQL> Insert into manages(employeeid,managerid) values(004,1003);


Output: 1 row created

Syntax: SQL> Insert into manages(employeeid,managerid) values(005,1005);


Output: 1 row created

Syntax: SQL>Insert into manages(employeeid,managerid) values(006,1004);


Output: 1 row created

Syntax: SQL>Insert into manages(employeeid,managerid) values(007,1002);


Output: 1 row created

Syntax: SQL> Insert into manages(employeeid,managerid) values(008,1003);


Output: 1 row created

Syntax: SQL> Insert into manages(employeeid,managerid) values(009,1001);


Output: 1 row created

Syntax: SQL>Insert into manages(employeeid,managerid) values(010,1005);


Output: 1 row created

ARIHANT SIPANI

03713401711

Database Management System

BBA(GEN)2

Select operations
Syntax:
SQL>Select * from employee; Employeeid 001 002 003 004 005 006 007 008 009 010 employeename suyush sid depanshu vicky bhanu prashant keshav pooja sneha arihant street firozpur shahdara rajindernagar andheri geetacolony krishnanagar jhilmil anandvihar kkd laxminagar city punjab delhi mumbai mumbai delhi kolkata mumbai delhi punjab delhi

Syntax:
SQL>Select * from company; companyid 201 202 203 204 205 companyname firstbankcorporation firstbankcorporation orientalbank orientalbank firstbankcorporation city punjab delhi mumbai mumbai delhi

ARIHANT SIPANI

03713401711

Database Management System

BBA(GEN)2

Syntax:
SQL>Select * from works; Employeeid 001 002 003 004 005 006 007 008 009 010 companyid 201 203 204 205 202 201 203 204 205 202 salary 10000 15000 9000 8000 12000 14000 11000 9500 8000 6500

ARIHANT SIPANI

03713401711

Database Management System

BBA(GEN)2

Syntax:
SQL>Select * from works; Employeeid 001 002 003 004 005 006 007 008 009 010 managerid 1001 1002 1001 1003 1005 1004 1002 1003 1001 1005

ARIHANT SIPANI

03713401711

Database Management System

BBA(GEN)2

Queries execution
1st query: Fill the name of all employees who worls for first bank corporation.

Syntax: Select employee.employeename from employee,company,works where employee.employeeid=works.employeeid and company.companyid=works.worksid and companyname=firstbankcorporation;

Output: Employeename suyush Sid depanshu prashant sneha Arihant

ARIHANT SIPANI

03713401711

Database Management System

BBA(GEN)2

2nd query: find the names and cities of residence of all employee who works for
first bank corporation.

Syntax Select employee.employeename,employee.city from employee,company,works where employee.employeeid=works.employeeid and company.companyid=works.worksid and companyname=firstbankcorporation;

Output: Employeename suyush vicky bhanu prashant sneha Arihant city punjab mumbai delhi kolkata punjab delhi

ARIHANT SIPANI

03713401711

Database Management System

BBA(GEN)2

3rd query: find the names, cities and street of all employees who works for first
bank corporation and earn more than 10000/-.

Syntax: Select employee.employeename,employee.city,employee.street from employee,company,works where employee.employeeid=works.employeeid and company.companyid=works.worksid and companyname=firstbankcorporation and salary > 10000;

Output: Employeename bhanu prashant City delhi kolkata Street geetacolony krishnanagar

ARIHANT SIPANI

03713401711

Database Management System

BBA(GEN)2

4th query: find the employees who live in the same cities as the company for
which they works.

Syntax: select employeename from employee,company where employee.city=company.city;

Output: Employeename suyush bhanu Keshav pooja Arihant

ARIHANT SIPANI

03713401711

Database Management System

BBA(GEN)2

5th query: find the name of all the employees who do not works for first bank
corporation.

Syntax: Select employee.employeename from employee,company,works where employee.employeeid=works.employeeid and company.companyid=works.worksid and companyname not= firstbankcorporation;

Output: Employeename sid depaunshu Keshav Pooja

6th query: find the company that have the smallest payroll.

Syntax: select companyname from company,works where company.companyid=works.worksid and salary=(select min (salary) from works); Output: Company name First bank corporation

ARIHANT SIPANI

03713401711