SQL Program
SQL Program
Create a table Student with the following fields and insert at least 5 records into the table except for the
column Total.
Roll_No Integer Primary key
Name Varchar (25)
Batch Varchar (15)
Mark1 Integer
Mark1 Integer
Mark3 Integer
Total Integer
a) Update the column Total with the sum of Mark1, Mark2 and Mark3.
b) List the details of students in Commerce batch.
c) Display the name and total marks of students who are failed (Total < 90).
d) Display the name and batch of those students who scored 90 or more in Mark1 and Mark2.
e) Display the name of students in alphabetical order and in batch based.
f) Delete the student who scored below 30 in Mark3.
QUERIES
CREATE DATABASE StudentDB;
USE StudentDB;
CREATE TABLE Student (Roll_No integer primary key, Name varchar(25), Batch varchar(15),
Mark1 integer, Mark2 integer, Mark3 integer, Total integer);
d) SELECT Name, Batch FROM Student WHERE Mark1 >= 90 AND Mark2 >= 90;
a)
Roll_No Name Batch Mark1 Mark2 Mark3 Total
1 Ajith Commerce 65 76 86 227
2 Sujith Science 96 97 98 291
3 Lalu Humanities 58 64 60 182
4 Sabu Humanities 28 27 25 80
5 Kiran Science 45 38 29 112
b)
Roll_No Name Batch Mark1 Mark2 Mark3 Total
1 Ajith Commerce 65 76 86 227
c)
Name Total
Sabu 80
d)
Name Batch
Sujith Science
d)
Name Batch
Ajith Commerce
Lalu Humanities
Sabu Humanities
Kiran Science
Sujith Science
e)
Roll_No Name Batch Mark1 Mark2 Mark3 Total
1 Ajith Commerce 65 76 86 227
2 Sujith Science 96 97 98 291
3 Lalu Humanities 58 64 60 182
Experiment No:
AIM
Create a table Employee with the following fields and insert at least 5 records into the table except
the column Gross_pay and DA.
Emp_code Integer Primary key
Emp_name Varchar (20)
Designation Varchar (25)
Department Varchar (25)
Basic Decimal (10, 2)
DA Decimal (10, 2)
Gross_pay Decimal (10, 2)
a) Update DA with 75% of Basic.
b) Update the Gross_pay with the sum of Basic and DA.
c) Display the details of employees in Purchase, Sales and HR departments.
d) Display the details of employee with gross pay below 10000.
e) Delete all the data from the table.
QUERIES
USE EmployeeDB;
a)
Emp_code Emp_name Designation Department Basic DA Gross_pay
101 Salim Clerk HR 11300. 00 8475. 00
102 Ajay Cashier Accounts 13700. 00 10275. 00
103 Balu Manager Sales 33500. 00 25125. 00
104 Usha Clerk Purchase 11300. 00 8475. 00
105 Hari Peon Sales 5200. 00 3900. 00
b)
Emp_code Emp_name Designation Department Basic DA Gross_pay
101 Salim Clerk HR 11300. 00 8475. 00 19775. 00
102 Ajay Cashier Accounts 13700. 00 10275. 00 23975. 00
103 Balu Manager Sales 33500. 00 25125. 00 58625. 00
104 Usha Clerk Purchase 11300. 00 8475. 00 19775. 00
105 Hari Peon Sales 5200. 00 3900. 00 9100. 00
c)
Emp_code Emp_name Designation Department Basic DA Gross_pay
101 Salim Clerk HR 11300. 00 8475. 00 19775. 00
103 Balu Manager Sales 33500. 00 25125. 00 58625. 00
104 Usha Clerk Purchase 11300. 00 8475. 00 19775. 00
105 Hari Peon Sales 5200. 00 3900. 00 9100. 00
d)
Emp_code Emp_name Designation Department Basic DA Gross_pay
101 Salim Clerk HR 11300. 00 8475. 00 19775. 00
103 Balu Manager Sales 33500. 00 25125. 00 58625. 00
104 Usha Clerk Purchase 11300. 00 8475. 00 19775. 00
e)
Emp_code Emp_name Designation Department Basic DA Gross_pay
Experiment No:
AIM
Create a table Stock, which stores daily sales of items in a shop, following fields and insert at least
5 records into the table.
Item_code Integer Primary key
Item_name Varchar (20)
Manufacturer_code Varchar (5)
Qty Integer
Unit_price Decimal (10, 2)
a) Display the item names with stock zero.
b) Display the number of items manufactured by the same manufacturer.
c) Display the highest price and lowest quantity in the stock.
d) Increase the unit price of all items by 10%.
QUERIES
USE StockDB;
a)
Item_name
Butter
b)
Manufacturer_code COUNT( * )
Ida 1
Itc 1
Rkg 2
Sata 2
c)
d)
AIM
Create a table Bank with the following fields and insert at least 5 records into the table.
Acc_no Integer Primary key
Acc_name Varchar (20)
Branch_name Varchar (25)
Acc_type Varchar(10)
Amount Decimal (10, 2)
a) Display the account details of “Savings Account” in Kodungallur branch.
b) Change the branch name “Trivandrum” to “Thiruvananthapuram”.
c) Display the details of customers in Thiruvananthapuram, Ernakulam and Kozhikode.
d) List the details of customers in Thrissur branch having a minimum balance of Rs. 5000.
QUERIES
USE BankDB;
a)
b)
Acc_no Acc_name Branch_name Acc_type Amount
1001 Javed Thiruvananthapuram SB 25000. 00
1002 Biju Kodungallur SB 30000. 00
1003 Shaji Thrissur Current 2000. 00
1004 Salim Kozhikode SB 18000. 00
1005 Rahul Ernakulam Current 4000. 00
1006 Thomas Kodungallur Current 2500. 00
1007 Nivin Thrissur SB 15000. 00
c)
Acc_no Acc_name Branch_name Acc_type Amount
1001 Javed Thiruvananthapuram SB 25000. 00
1004 Salim Kozhikode SB 18000. 00
1005 Rahul Ernakulam Current 4000. 00
d)