You are on page 1of 2

SQL 1: ELECTRICITY BILL DATABASE

Create table electricity for the following fields:

Field Name Type


rrno varchar2(10)
cname varchar2(10)
datebilling Date
units number(4)

create table electricity (rrno varchar2(10), cname varchar2(10),


datebilling date, units number(4));

I. Inserts five values(records) into electricity table.

insert into electricity values (‘101’ , ‘ABHI’ , ’01 – jan – 2022’ , 130);
insert into electricity values (‘102’ , ‘ROHIT’ , ’21 – dec – 2021’ , 110);
insert into electricity values (‘103’ , ‘RAHUL’, ’10 – feb – 2022’ , 90);
insert into electricity values (‘104’ , ‘MANOJ’, ’6 – mar – 2022’ , 78);
insert into electricity values (‘105’, ‘MADAN’, ’8 – jun – 2021’ , 115);

II. Describe the structure of table.


desc electricity ;

III. Alter table electricity and Add two new fields to the table.
a. billamt number(6,2), duedate date

alter table electricity add (billamt number(6,2) , duedate date);

IV. Calculate bill amount for each consumer as per the following
rules.
a. Min_amt Rs. 50
b. First 100 units Rs. 4.50/unit
c. >100 units Rs. 5.50/unit

a. update electricity set billamt = 50;


b. update electricity set billamt = billamt + units * 4.5
where units <= 100;
c. update electricity set billamt = billamt + 100 * 4.5 + (units-100) * 5.5
where units > 100;

V. Compute due date as billing date + 15days.


update electricity set duedate = datebilling + 15;

VI. List all the bills generated


select * from electricity ;
SQL 2: STUDENT DATABASE

Create table student for the following fields:


Field name Type
sid number(4)
sname varchar2(10)
m1 number(3)
m2 number(3)
m3 number(3)
m4 number(3)
m5 number(3)
m6 number(3)
create table student(sid number(4), sname varchar2(10), m1 number(3), m2
number(3), m3 number(3), m4 number(3), m5 number(3), m6 number(3));

I. Inserts five values(records) into student table.


insert into student values(1, ‘ROHIT’, 78, 88, 79, 80, 89, 87);
insert into student values(2, ‘RAJ’, 78, 88, 79, 80, 89, 87);
insert into student values(3, ‘RAJANI’, 78, 88, 29, 80, 19, 87);
insert into student values(4, ‘ROSHAN’, 78, 88, 79, 80, 89, 87);
insert into student values(5, ‘RAM’, 78, 28, 79, 80, 89, 17);

II. Alter table student and add the following field


a. total number(3), perc float, result varchar2(5)
alter table student add(total number(3), perc float, result varchar2(5));

III. calculate total marks for all the students

update student set total = m1 + m2 + m3 + m4 + m5 + m6;

IV. calculate percentage for all the students


update student set perc = total / 6;

V. Compute the result as “Pass”


update student set result = ‘Pass’
where m1>=35 and m2>=35 and m3>=35 and m4>=35 and m5>=35 and
m6>= 35;

VI. Compute the result as “Fail”


update student set result = ‘fail’
where m1<35 or m2<35 or m3<35 or m4<35 or m5<35 or m6<35;

VII. View the contents of the table


select * from student;

You might also like