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

SQL Program

Uploaded by

offx.fadhal
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

SQL Program

Uploaded by

offx.fadhal
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

Part – C

Database queries using MySQL


Experiment No.
AIM

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);

INSERT INTO Student (Roll_No, Name, Batch, Mark1, Mark2, Mark3)


VALUES (1, "Ajith", "Commerce", 65, 76, 86);

INSERT INTO Student (Roll_No, Name, Batch, Mark1, Mark2, Mark3)


VALUES (2, "Sujith”, "Science", 96, 97, 98);

INSERT INTO Student (Roll_No, Name, Batch, Mark1, Mark2, Mark3)


VALUES (3, "Lalu”, "Humanities", 58, 64, 60);

INSERT INTO Student (Roll_No, Name, Batch, Mark1, Mark2, Mark3)


VALUES (4, "Sabu”, "Humanities", 28, 27, 25);

INSERT INTO Student (Roll_No, Name, Batch, Mark1, Mark2, Mark3)


VALUES (5, "Kiran”, "Science", 45, 38, 29);

a) UPDATE Student SET Total=Mark1 + Mark2 + Mark3;

b) SELECT * FROM Student WHERE Batch = "Commerce”;

c) SELECT Name, Total FROM Student WHERE Total < 90;

d) SELECT Name, Batch FROM Student WHERE Mark1 >= 90 AND Mark2 >= 90;

f) SELECT Name, Batch FROM Student ORDER BY Batch, Name;

e) DELETE FROM Student WHERE Mark3 < 30;


DATABASE

Roll_No Name Batch Mark1 Mark2 Mark3 Total


1 Ajith Commerce 65 76 86
2 Sujith Science 96 97 98
3 Lalu Humanities 58 64 60
4 Sabu Humanities 28 27 25
5 Kiran Science 45 38 29

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

CREATE DATABASE EmployeeDB;

USE EmployeeDB;

CREATE TABLE EMPLOYEE(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));

INSERT INTO Employee(Emp_code, Emp_name, Designation, Department, Basic)


VALUES (101, 'Salim', 'Clerk', 'HR', 11300);

INSERT INTO Employee(Emp_code, Emp_name, Designation, Department, Basic)


VALUES (102, 'Ajay', 'Cashier', 'Accounts', 13700);

INSERT INTO Employee(Emp_code, Emp_name, Designation, Department, Basic)


VALUES (103, 'Balu', 'Manager', 'Sales', 33500);

INSERT INTO Employee(Emp_code, Emp_name, Designation, Department, Basic)


VALUES (104, 'Usha','Clerk', 'Purchase', 11300);

INSERT INTO Employee(Emp_code, Emp_name, Designation, Department, Basic)


VALUES (105, 'Hari', 'Peon', 'Sales', 5200);

a) UPDATE Employee SET DA=Basic*75/100;

b) UPDATE Employee SET Gross_pay=Basic+DA;

c) SELECT * FROM Employee WHERE Department IN ('HR', 'Sales', 'Purchase');

d) SELECT * FROM Employee WHERE Gross_pay<10000;

e) DELETE FROM Employee;


DATABASE

Emp_code Emp_name Designation Department Basic DA Gross_pay


101 Salim Clerk HR 11300. 00
102 Ajay Cashier Accounts 13700. 00
103 Balu Manager Sales 33500. 00
104 Usha Clerk Purchase 11300. 00
105 Hari Peon Sales 5200. 00

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

CREATE DATABASE StockDB;

USE StockDB;

CREATE TABLE Stock(Item_code integer primary key, Item_name varchar(20),


Manufacturer_code varchar(5), Qty integer, Unit_price decimal(10,2));

INSERT INTO Stock(Item_code, Item_name, Manufacturer_code, Qty, Unit_price)


VALUES (101, 'Colgate', 'Ida', 30, 29.50);

INSERT INTO Stock(Item_code, Item_name, Manufacturer_code, Qty, Unit_price)


VALUES (102, 'Pears', 'Itc', 25, 49.00);

INSERT INTO Stock(Item_code, Item_name, Manufacturer_code, Qty, Unit_price)


VALUES (103, 'Ghee', 'Rkg', 15, 249.90);

INSERT INTO Stock(Item_code, Item_name, Manufacturer_code, Qty, Unit_price)


VALUES (104, 'Facewash', 'Sata', 18, 35.00);

INSERT INTO Stock(Item_code, Item_name, Manufacturer_code, Qty, Unit_price)


VALUES (105, 'Powder', 'Sata', 19, 35.00);

INSERT INTO Stock(Item_code, Item_name, Manufacturer_code, Qty, Unit_price)


VALUES (106, 'Butter', 'Rkg', 0, 175.50);

a) SELECT Item_name FROM Stock WHERE Qty=0;

b) SELECT Manufacturer_code, COUNT(*) FROM Stock GROUP BY Manufacturer_code;

c) SELECT MAX(Unit_price), MIN(Qty) FROM Stock;

d) UPDATE Stock SET Unit_price=Unit_price+(Unit_price*10/100);


DATABASE

Item_code Item_name Manufacturer_code Qty Unit_price


101 Colgate Ida 30 29.50
102 Pears Itc 25 49.00
103 Ghee Rkg 15 249.90
104 Facewash Sata 18 35.00
105 Powder Sata 19 24.99
106 Butter Rkg 0 175.50

a)
Item_name
Butter

b)

Manufacturer_code COUNT( * )
Ida 1
Itc 1
Rkg 2
Sata 2

c)

MAX(Unit_price) MIN( Qty)


249.90 0

d)

Item_code Item_name Manufacturer_code Qty Unit_price


101 Colgate Ida 30 32.45
102 Pears Itc 25 53.90
103 Ghee Rkg 15 274.89
104 Facewash Sata 18 38.50
105 Powder Sata 19 27.49
106 Butter Rkg 0 193.05
Experiment No:

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

CREATE DATABASE BankDB;

USE BankDB;

CREATE TABLE Bank(Acc_no integer primary key, Acc_name varchar(20),


Branch_name varchar(25), Acc_type varchar(10), Amount decimal(10,2));

INSERT INTO Bank(Acc_no, Acc_name, Branch_name, Acc_type, Amount)


VALUES (1001, 'Javed', 'Trivandrum', 'SB', 25000);

INSERT INTO Bank(Acc_no, Acc_name, Branch_name, Acc_type, Amount)


VALUES (1002, 'Biju', 'Kodungallur', 'SB', 30000);

INSERT INTO Bank(Acc_no, Acc_name, Branch_name, Acc_type, Amount)


VALUES (1003, 'Shaji', 'Thrissur', 'Current', 2000);

INSERT INTO Bank(Acc_no, Acc_name, Branch_name, Acc_type, Amount)


VALUES (1004, 'Salim', 'Kozhikode', 'SB', 18000);

INSERT INTO Bank(Acc_no, Acc_name, Branch_name, Acc_type, Amount)


VALUES (1005, 'Rahul', 'Ernakulam', 'Current', 4000);

INSERT INTO Bank(Acc_no, Acc_name, Branch_name, Acc_type, Amount)


VALUES (1006, 'Thomas', 'Kodungallur', 'Current', 2500);

INSERT INTO Bank(Acc_no, Acc_name, Branch_name, Acc_type, Amount)


VALUES (1007, 'Nivin', 'Thrissur', 'SB', 15000);

a) SELECT * FROM Bank WHERE Acc_type='SB' AND Branch_name='Kodungallur';

b) UPDATE Bank SET Branch_name='Thiruvananthapuram' WHERE Branch_name='Trivandrum';

c) SELECT * FROM Bank WHERE Branch_name IN ('Thiruvananthapuram', 'Ernakulam', 'Kozhikode');

d) SELECT * FROM Bank WHERE Branch_name='Thrissur' AND Amount>=5000;


DATABASE

Acc_no Acc_name Branch_name Acc_type Amount


1001 Javed Trivandrum 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

a)

Acc_no Acc_name Branch_name Acc_type Amount


1002 Biju Kodungallur SB 30000. 00

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)

Acc_no Acc_name Branch_name Acc_type Amount


1007 Nivin Thrissur SB 15000. 00

You might also like