Cs Lab
Cs Lab
Cs Lab
Create a table Student with the following fields and insert at least 5 records into the table except for the column
Total.
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. Delete the student who scored below 30 in Mark3.
SQL statements :
a. UPDATE student
SET Total=Mark1+Mark2+Mark3;
1
GVHSS ATHOLI, KOZHIKODE SANTHOSH KUMAR K.P.
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;
e. DELETE
FROM STUDENT
WHERE Mark3<30;
Output of Queries
b. 2 rows in set.
c. 2 rows in set.
d. 2 rows in set.
2
GVHSS ATHOLI, KOZHIKODE SANTHOSH KUMAR K.P.
SQL-2 (Employee)
Table structure and queries :
Create a table Employee with the following fields and insert at least 5 records into the table except the column
Gross_pay and DA.
SQL statements :
1. SQL Query to create the table .
CREATE TABLE Employee
(
Emp_code INT PRIMARY KEY,
Emp_name VARCHAR (20),
Designation VARCHAR(25),
Department VARCHAR(25),
Basic DEC(10,2),
DA DEC(10,2),
Gross_pay DEC(10,2)
);
2. SQL Query to insert 5 records into the table
I. INSERT INTO Employee (Emp_code , Emp_name, Designation, Department, Basic)
VALUES (1, ’Rahul’, ’clerk’, ‘sales’, 5000);
II. INSERT INTO Employee (Emp_code , Emp_name, Designation, Department, Basic) VALUES (2,
’Abraham’, ’supervisor’, ‘purchase’, 9000);
III. INSERT INTO Employee (Emp_code , Emp_name, Designation, Department, Basic)
VALUES (3, ’Roshan’, ’officer’, ‘HR’ , 12000);
IV. INSERT INTO Employee (Emp_code , Emp_name, Designation, Department, Basic)
VALUES (4, ’Soumya’, ’supervisor’, ‘stock’, 4000);
V. INSERT INTO Employee (Emp_code , Emp_name, Designation, Department, Basic)
VALUES (5, ’Anusree’, ’clerk’, ‘purchase’, 3000);
a. UPDATE Employee
SET DA = Basic * 75 /100 ;
b. SELECT * FROM Employee
WHERE Department IN (‘sales’, ’purchase’, ’HR’);
3
GVHSS ATHOLI, KOZHIKODE SANTHOSH KUMAR K.P.
c. UPDATE Employee
SET Gross_pay = Basic + DA;
d. SELECT * FROM Employee
WHERE Gross_pay < 10000;
e. DELETE
FROM Employee
WHERE Designation = ‘clerk’ ;
Output of Queries
b. 4 rows in set.
d. 3 rows in set.
4
GVHSS ATHOLI, KOZHIKODE SANTHOSH KUMAR K.P.
SQL-3 (Stock)
Table structure and queries :
Create a table Stock, which stores daily sales of items in a shop, with the following fields and insert at least 5
records into the table.
a. Display the details of items which expire after 31/3/2016 in the order of expiry date.
b. Find the number of items manufactured by the company “SATA”.
c. Remove the items which expire between 31/12/2015 and 01/06/2016.
d. Add a new column named Reorder in the table to store the reorder level of items.
e. Update the column Reorder with value obtained by deducting 10% of the current stock.
SQL statements :
Output of Queries
a. 3 rows in set
b. 1 row in set.
6
GVHSS ATHOLI, KOZHIKODE SANTHOSH KUMAR K.P.
SQL-4 (Book)
Table structure and queries :
Create a table Book with the following fields and insert at least 5 records into the table.
SQL statements :
Output of Queries
b. 3 rows in set.
c. 1 row in set.
d. 3 rows in set.
e. 5 rows in set.
8
GVHSS ATHOLI, KOZHIKODE SANTHOSH KUMAR K.P.
SQL-5 (Bank)
Table structure and queries :
Create a table Bank with the following fields and insert at least 5 records into the table.
a. Display the branch-wise details of account holders in the ascending order of the amount.
b. Insert a new column named Minimum_Amount into the table with default value 1000.
c. Update the Minimum_Amount column with the value 500 for the customers in branches other than
Alappuzha and Malappuram.
d. Find the number of customers who do not have the minimum amount 1000.
e. Remove the details of SB accounts from Thiruvananthapuram branch who have zero (0) balance in their
account.
SQL statements :
1. SQL Query to create the table .
Output of Queries
a. 5 rows in set
d. 1 row in set.
10
GVHSS ATHOLI, KOZHIKODE SANTHOSH KUMAR K.P.