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

1,2,3,4

Project

Uploaded by

suchina605
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

1,2,3,4

Project

Uploaded by

suchina605
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 15

Name : Akash Class : 2nd BCA B Rollno : CA23404

1.Create table employee using SQL command to store details of employee. Such as empno,
name, designation, department, gender, and salary. Specify primary key and not null
constraints on the table.
Allow only ‘M’ or ‘F’ for the column gender.
Department can be sales, accounts, IT.
Choose designation as clerk, analyst, manager, accountant and supervisor that depends on
department.
Write the following SQL quries:
A) Display EMPNO,NAME and DESIGNATION of all employees whose name ends
with RAJ.
B) Display the details of all female employees who is earning salary within the range
20000 to 40000 in SALES or IT departments.
C) List the different DEPARTMENTs with the DISGNATIONs in that department.
D) Display the department name,total,average,maximum,minimumsalary of the
DEPARTMENT only if the total salary given in that department is more than
30000.
E) List the departments which have more than 2 employees.

Creating the table:


create table emp123
(
emp_no number(15) primary key,
name varchar(5) not null,
gender varchar(1) check( gender in('F','M')),
department varchar(10) check(department in('sales','accounts','IT')),
designation varchar(10) check(designation in('clerk','accountant','supervisor','manager','analyst')),
salary number(15,5) not null
);
Table created.

Structure of Table:

Inserting values into table


SQL> insert into emp12345 values(110,'megha','F','IT','manager',30000);
1 row created.

SQL> insert into emp12345 values(111,'suraj','M','sales','supervisor',35000);


1 row created.

SQL> insert into emp12345 values(112,'diraj','M','sales','accountant',25000);

Alvas College Moodbidri


Name : Akash Class : 2nd BCA B Rollno : CA23404

1 row created.

SQL> insert into emp12345 values(113,'viraj','M','accounts','analyst',25000);


1 row created.

SQL> insert into emp12345 values(114,'geeta','F','IT','clerk',25000);


1 row created.

SQL> insert into emp12345 values(115,'rose','F','sales','clerk',28000);


1 row created.

Displaying values of table:

Write the following SQL quries:


A) Display EMPNO,NAME and DESIGNATION of all employees whose name ends
with RAJ.

B) Display the details of all female employees who is earning salary within the range
20000 to 40000 in SALES or IT departments.
SQL> select *from emp12345 where gender ='F' and (salary between 20000 and 40000)and
department in('sales','IT');
EMP_NO NAME G DEPARTMENT DESIGNATIO SALARY
---------- ----- - ---------- ---------- ----------
110 megha F IT manager 30000
114 geeta F IT clerk 25000
115 rose F sales clerk 28000

Alvas College Moodbidri


Name : Akash Class : 2nd BCA B Rollno : CA23404

C) List the different DEPARTMENTs with the DISGNATIONs in that department.

D) Display the department name,total,average,maximum,minimumsalary of the


DEPARTMENT only if the total salary given in that department is more than
30000
SQL> select department,sum(salary)"total
salary",avg(salary)"average",max(salary)"maximum",min(salary)"minimum"from emp12345
group by department having sum(salary)>30000;

DEPARTMENT total salary average maximum minimum


---------- ------------ ---------- ---------- ----------
IT 55000 27500 30000 25000
sales 88000 29333.333 35000 25000

E) List the departments which have more than 2 employees.


SQL> select department ,count(name)"number of employee"from emp12345 group by
department having count(name)>2;

DEPARTMENT number of employee


---------- ------------------
sales 3

Alvas College Moodbidri


Name : Akash Class : 2nd BCA B Rollno : CA23404

2. Create a table CLIENT to store Client_no, Name, Address, State, Bal_Due. Client no must
start with ‘C’. Apply the suitable structures for the columns. Specify primary key and NOT
NULL constraints on the table.
Insert 10 records.
Write the following SQL queries:
a) From the table CLIENT, create a new table CLIENT1 that contains only CLIENT_NO and
NAME, BAL_DUE from specified STATE. Accept the state during run time.
b) create a new table CLIENT2 that has the same structure as CLIENT but with no records.
Display the structure and records.
c) Add a new column by name PENALTY number (10, 2) to the CLIENT.
d) Assign Penalty as 10% of BAL_DUE for the clients C1002, C1005, C1009 and for others
8%. Display Records.
e) Change the name of CLIENT1 as NEW_CLIENT.
f) Delete the table CLIENT2.

Creating Table:
create table client(clientno varchar(10) primary key,
name varchar(10) not null,
adress varchar(20) not null,
state varchar(10) not null,
bal_due number(7),
check (clientno like 'C%'));

Displaying Table:

Inserting values to the Table:


SQL> insert into client values('C1001','Akash','karkala','Karnataka',40000);
1 row created.

SQL> insert into client values('C1002','Trupthi','Udupi','Karnataka',45000);


1 row created.

SQL> insert into client values('C1003','Roshan','Kannur','Kerala',14000);


1 row created.

Alvas College Moodbidri


Name : Akash Class : 2nd BCA B Rollno : CA23404

SQL> insert into client values('C1004','Suchin','karkala','Karnataka',24000);


1 row created.
SQL> insert into client values('C1005','Amith','Jaipur','Rajasthan',40000);
1 row created.
SQL> insert into client values('C1006','Manja','Hubballi','Karnataka',17000);
1 row created.
SQL> insert into client values('C1007','Suvin','Chennai','Tamilnadu',30000);
1 row created.
SQL> insert into client values('C1008','Ranjith','Panaji','Goa',22000);
1 row created.
SQL> insert into client values('C1009','Ranjitha','Kalasa','Karnataka',18000);
1 row created.
SQL> insert into client values('C1010','Thanush','Mumbai','Maharastra',13000);
1 row created.
Displaying the values in the table:

Write the following SQL queries:


a) From the table CLIENT, create a new table CLIENT1 that contains only
CLIENT_NO and NAME , BAL_DUE from specified STATE. Accept the state during
run time.
SQL> create table client1 (clientno,name,bal_due) as select clientno,name,bal_due from client
where state = '&state';
Enter value for state: Karnataka

Alvas College Moodbidri


Name : Akash Class : 2nd BCA B Rollno : CA23404

old 1: create table client1 (clientno,name,bal_due) as select clientno,name,bal_due from client


where state = '&state'
new 1: create table client1 (clientno,name,bal_due) as select clientno,name,bal_due from client
where state = 'Karnataka'
Table created.

b) create a new table CLIENT2 that has the same structure as CLIENT but with no
records. Display the structure and records.
SQL> create table client2 (clientno,name,adress,state,bal_due) as select
clientno,name,adress,state,bal_due from client where 1=2;
Table created.

c) Add a new column by name PENALTY number (10, 2) to the CLIENT.


SQL> alter table client add(penalty number(10,2));
Table altered.

Alvas College Moodbidri


Name : Akash Class : 2nd BCA B Rollno : CA23404

d) Assign Penalty as 10% of BAL_DUE for the clients C1002, C1005, C1009 and for
others 8%. Display Records.
SQL> update client set penalty = 0.1*bal_due where clientno in('C1001','C1005','C1009');
3 rows updated.

SQL> update client set penalty = 0.08*bal_due where clientno not in('C1001','C1005','C1009');
7 rows updated.

e) Change the name of CLIENT1 as NEW_CLIENT.


SQL> rename client1 to new_client;
Table renamed.

Alvas College Moodbidri


Name : Akash Class : 2nd BCA B Rollno : CA23404

f) Delete the table CLIENT2.


SQL> drop table client2;

Table dropped.

SQL> select *from client2;


select *from client2
*
ERROR at line 1:
ORA-00942: table or view does not exist

Alvas College Moodbidri


Name : Akash Class : 2nd BCA B Rollno : CA23404

3. Create a table BOOK using SQL command to store Accession No, TITLE, AUTHOR,
PUBLISHER, YEAR, PRICE. Apply the suitable structure for the columns. Specify Primary
Key and NOT NULL constraints on the table. Insert 10 records.
Write the following SQL queries:
a) List the details of publishers having ‘a’ as the second character in their names.
b) Display Accession No., TITLE, PUBLISHER and YEAR of the books published by the
specified author before 2010 in the descending order of YEAR. Accept author during
runtime.
c) Modify the size of TITLE to increase the size 5 characters more.
d) Display the details of all books other than Microsoft press publishers.
e) Remove the records of the books published before 1990.

Creating Table:
SQL> create table book480(
2 accession_no number(5) primary key,
3 title varchar(20) not null,
4 author varchar(20) not null,
5 publisher varchar(20) not null,
6 year number(4) not null,
7 price number(10,2) not null);
Table created

Describing Table:
SQL> desc book480;

Inserting values into table:


SQL> insert into book480 values(1001,'JAVA','Robert','Microsoft Press',1995,450);

SQL> insert into book480 values(3288,'C','William','English Publisher',2020,3750);

SQL> insert into book480 values(4335,'Hindi','Mahathma','Kavya publisher',2005,2700);

SQL> insert into book480 values(3685,'Kannada','Kuvempu','Ram publisher',2013,1500);

SQL> insert into book480 values(4858,'Classmate','Sarathi','Sarathi Press',2023,3599);

SQL> insert into book480 values(0655,'Speed','David','Australia Publisher',1967,4550);

SQL> insert into book480 values(2675,'Bharath','Baskar','Book Tech',2017,450);.

Alvas College Moodbidri


Name : Akash Class : 2nd BCA B Rollno : CA23404

SQL> insert into book480 values(4685,'Excel','Bairstow','Microsoft Press',2002,6730);

SQL> insert into book480 values(8676,'C#','Romeo','Visual Publisher',1965,3570);

SQL> insert into book480 values(3677,'DBMS','Robin','Microsoft Press',2018,6890);

Displaying table:
SQL> select *from book480;

a) List the details of publishers having ‘a’ as the second character in their names.
SQL> select *from book480 where publisher like '_a%';

b) Display Accession No., TITLE, PUBLISHER and YEAR of the books published by the
specified author before 2010 in the descending order of YEAR. Accept author during
runtime.
SQL> select accession_no,title,publisher,year from book480 where(year<2010 and
author='&author')order by year desc;
Enter value for author: David
old 1: select accession_no,title,publisher,year from book480 where(year<2010 and
author='&author')order by year desc
new 1: select accession_no,title,publisher,year from book480 where(year<2010 and
author='David')order by year desc

Alvas College Moodbidri


Name : Akash Class : 2nd BCA B Rollno : CA23404

c) Modify the size of TITLE to increase the size 5 characters more.


SQL> alter table book480
2 modify title varchar(25);
Table altered.
SQL> desc book480;

d) Display the details of all books other than Microsoft press publishers.
SQL> select *from book480 where publisher not in('Microsoft Press');

e) Remove the records of the books published before 1990.


SQL> delete from book480 where year<1990;
2 rows deleted.
SQL> select*from book480;

Alvas College Moodbidri


Name : Akash Class : 2nd BCA B Rollno : CA23404

4. Create a table SALES with columns SNO, SNAME, MANAGER_NAME, JOIN_DATE,


DATE_BIRTH, SALARY,SALES_AMOUNT and COMMISSION. Minimum age for joining
the company must be 18 Yrs. Default value for Commission should be 0. Apply the suitable
structure for the columns. Specify Primary Key and NOT NULL constraints on the table.
Insert 10 records with data except commission. Manager of Manager can be NULL.
Write the following SQL queries:
a) Display the details of Sales Persons whose salary is more than Average salary in the
company.
b) Update commission as 20% of Sales Amount.
c) Display SNO, SNAME, MANAGER_NAME, SALARY, COMMISSION,
MANAGER_SALARY of the sales persons getting sum of salary and commission more than
salary of manager.(Self join)
d) Display the records of employees who finished the service of 10years.
Creating table:
SQL> create table sale(
2 sno varchar(5)primary key,
3 sname varchar(19)not null,
4 manager_no varchar(10),
5 DOJ date,
6 DOB date,
7 salary number(8,2)not null,
8 sales_amount number(8,2)not null,
9 commission number(8,2)default 0,
10 check (round((DOJ-DOB)/365)>18));
Table created.

Displaying table structure:

Inserting values:
SQL> insert into sale(sno,sname,DOJ,DOB,salary,sales_amount)values('C1001','sai','12-jan-
14','12-may-91',49000,24000);

Alvas College Moodbidri


Name : Akash Class : 2nd BCA B Rollno : CA23404

SQL> insert into


sale(sno,sname,manager_no,DOJ,DOB,salary,sales_amount)values('C1002','uday','C1001','18-
mar-19','23-oct-95',35000,28000);

SQL> insert into


sale(sno,sname,manager_no,DOJ,DOB,salary,sales_amount)values('C1003','ravi','C1001','25-
feb-21','09-apr-87',24000,18000);

SQL> insert into


sale(sno,sname,manager_no,DOJ,DOB,salary,sales_amount)values('C1004','srajan','C1002','07-
jan-23','01-apr-94',28000,23000);

SQL> insert into


sale(sno,sname,manager_no,DOJ,DOB,salary,sales_amount)values('C1005','manja','C1004','26-
jul-22','03-jan-87',25500,17000);

SQL> insert into


sale(sno,sname,manager_no,DOJ,DOB,salary,sales_amount)values('C1006','roshan','C1004','15-
jan-23','17-feb-97',27000,15000)

SQL> insert into


sale(sno,sname,manager_no,DOJ,DOB,salary,sales_amount)values('C1007','suvin','C1003','10-
may-24','28-dec-84',44300,26000);

SQL> insert into


sale(sno,sname,manager_no,DOJ,DOB,salary,sales_amount)values('C1008','durga','C1002','17-
sep-19','27-oct-99',34000,24000);
.

SQL> insert into


sale(sno,sname,manager_no,DOJ,DOB,salary,sales_amount)values('C1009','suchin','C1003','05-
nov-17','11-nov-82',39000,26000);

SQL> insert into


sale(sno,sname,manager_no,DOJ,DOB,salary,sales_amount)values('C1010','amith','C1004','14-
dec-20','16-aug-86',19000,14000);

Displaying table values:

Alvas College Moodbidri


Name : Akash Class : 2nd BCA B Rollno : CA23404

a) Display the details of Sales Persons whose salary is more than Average salary in the
company.
select *from sale where salary > (select avg(salary) from sale);

b) Update commission as 20% of Sales Amount.


update sale set commission = sales_amount*0.2;

c) Display SNO, SNAME, MANAGER_NAME, SALARY, COMMISSION,


MANAGER_SALARY of the sales persons getting sum of salary and commission more than
salary of manager.(Self join)

Alvas College Moodbidri


Name : Akash Class : 2nd BCA B Rollno : CA23404

d) Display the records of employees who finished the service of 10years.


select *from sale where (round((sysdate-DOJ)/365)>10);

Alvas College Moodbidri

You might also like