SQL Programs
SQL Programs
1. create table ele (RRno varchar(10), name char(25), billdate date, units int(4));
3. desc ele;
4. alter table ele add(billamt decimal, duedate date);
5. select * from ele;
6. update ele Set billamt=50+units*4.50 where units<=100;
7. update ele set billamt=50+100*4.50+(units-100)*5.50 where units>100;
8. update ele Set duedate=billdate+15;
9. select * from ele;
SQL Problem No .2
Name type
Std_id Number(2)
Std_name Varchar2(10)
Sub1_marks Number(2)
Sub2_marks Number(2)
Sub3_marks Number(2)
Sub4_marks Number(2)
Sub5_marks Number(2)
Sub6_marks Number(2)
1. Add records into the table for 10 students for std_id, std_name and 6 subject marks using insert
command
2. Display the description of the fields in the table using desc command
4. Compute the result as “pass” or “fail” by checking if the student has scored more than 35 marks in
each subject
1. create table std (Id int(4), Name char(10),S1 int(2),S2 int (2),S3 int(2), S4 int(2) ,S5 int(2),S6 int(2));
7. update std set res=’pass’ where (s1>=35 and s2>=35 and s3>=35 and s4>=35 and s5>=35 and
s6>=35);
8. update std set res=’fail’ where (s1<35 or s2<35 or s3<35 or s4<35 or s5<35 or s6<35);
Emp-id Number(4)
Dept-id Number(2)
Emp-name Varchar(10)
Emp-salary Number(5)
Dept-id Number(2)
Dept-name Varchar(10)
supervisor Varchar(10)
Dept-name Dept-id
Purchase 1
Accounts 2
Sales 3
Apprentice 4
1. Enter 10 rows of data for table employee and 4 rows of data for department table
2. Find the names of all employees who work for the accounts department
3. How many employees work for accounts department
4. What is the minimum, maximum and average salary of employees working for accounts department
5. List the employees working for a particular supervisor
6. Retrieve the department names for each departments where only 1 employee works
1. create table emp(Id int(4),did int (2), name varchar(10) ,sal int(5));
7. select * from emp where did =(select did from dep where dname =’accounts’);
8. select count (*) from emp where did =(select did from dep where dname=’Accounts’);
9. select min(sal),max(sal),avg(sal) from emp where did =(select did from dep where
dname=’Accounts’);
10. select * from emp where did =(select did from dep where supervisor=’suman’);
11. select dname from dep where did in (select did from emp groupby did having count(*)=1);
12. update emp set sal=sal+sal*0.15 where did=(select did from dep where dname =’sales’);
15. delete from emp where did = (select did from dep where name=’Apprentice’);
SQL problem no.4
Create the following table BANK DATABASE for the ABC bank with the following structure:
1. Find the names of all customer whose balance amount is more than Rs.30,000/-.
2. How many customer whose balance amount is less than the minimum in the account (assume that
minimum balance is Rs.1000/-).
3. Perform the transaction on T_TYPE (Deposit or withdrawal).
4. Display transaction amount on a particular day.
5. Display all the records of CA account.
1. create table cust (cno int(4) primary key, name char(20), cadd varchar(20), mob char(8));
2. create table bank (accno int(4) not NULL, tamt int(8) check (tamt>0), tdate date, ttype char,
cno int(4));
14. create table tcust as (select *from cust where cno between 100 and 102);
20. select accno, count(*) from bank group by accno having count(*)>1;