2nd Assign DBMS
2nd Assign DBMS
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
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
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
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
BBA(GEN)2
ARIHANT SIPANI
03713401711
BBA(GEN)2
Company table
Inserting 5 rows in company table
BBA(GEN)2
Works
Inserting appropriate rows in works table
ARIHANT SIPANI
03713401711
BBA(GEN)2
Manages table
Inserting appropriate rows in manages table
ARIHANT SIPANI
03713401711
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
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
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
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;
ARIHANT SIPANI
03713401711
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
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
BBA(GEN)2
4th query: find the employees who live in the same cities as the company for
which they works.
ARIHANT SIPANI
03713401711
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;
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