Xii CA SQL Solved Lab Work
Xii CA SQL Solved Lab Work
VALUES(105,’Akku’,’Commerce’,90,88,66);
SELECT * FROM student;
Q1. Create a table Student with the following fields and insert at least
5 records into the table except for the column Total.
a) UPDATE Student SET Total=Mark1+Mark2+Mark3;
Roll_Number Integer Primary key
b) SELECT * FROM student WHERE Batch=’Commerce’;
Name Varchar (25)
c) SELECT Name ,Total FROM student WHERE Total < 90;
Batch Varchar (15)
d) SELECT Name , Batch FROM student WHERE Mark1>90 AND
Mark1 Integer
Mark2>90;
Mark2 Integer
e) DELETE FROM student WHERE Mark3 <30;
Mark3 Integer
Total Integer
OUTPUT:
a. Update the column Total with the sum of Mark1, Mark2 and Mark3.
Select * From students
b. List the details of students in Commerce batch.
-------------------------------------------------------------------------------
c. Display the name and total marks of students who are failed (Total <
| Roll_No | Name | Batch | Mark1 | Mark2 | Mark3 | Total |
90).
-------------------------------------------------------------------------------
d. Display the name and batch of those students who scored 90 or more in
| 101 | Aju | Science | 89 | 78 | 56 | NULL |
Mark1 and Mark2.
| 102 | Allu | Commerce | 23 | 12 | 15 | NULL |
e. Delete the student who scored below 30 in Mark3.
| 103 | Ammu| Humanities | 90 | 100 | 100 | NULL |
| 104 | Appu | Science | 12 | 23 | 13 | NULL |
SQL Statements: | 105 | Akku | Commerce | 90 | 88 | 66 | NULL |
Query for creating Student table -------------------------------------------------------------------------------
CREATE TABLE student(Roll_No INT PRIMARY KEY, Name a)
VARCHAR(25),Batch VARCHAR(15),Mark1 INT,Mark2 INT,Mark3 ------------------------------------------------------------------------------
INT,Total INT); | Roll_No | Name | Batch | Mark1 | Mark2 | Mark3 | Total |
Inserting values into Student table ------------------------------------------------------------------------------
INSERT INTO student (Roll_No,Name,Batch,Mark1,Mark2,Mark3) | 101 | Aju | Science | 89 | 78 | 56 | 223 |
VALUES(101,’Aju’,’Science’,89,78,56); | 102 | Allu | Commerce | 23 | 12 | 15 | 50 |
INSERT INTO student (Roll_No,Name,Batch,Mark1,Mark2,Mark3) | 103 | Ammu | Humanities | 90 | 100 | 100 | 290 |
VALUES(102,’Allu’,’Commerce’,23,12,15); | 104 | Appu | Science | 12 | 23 | 13 | 48 |
INSERT INTO student (Roll_No,Name,Batch,Mark1,Mark2,Mark3) | 105 | Akku | Commerce | 90 | 88 | 66 | 244 |
VALUES(103,’Ammu’,’Humanities’,90,100,100);
INSERT INTO student (Roll_No,Name,Batch,Mark1,Mark2,Mark3)
VALUES(104,’Appu’,’Science’,12,23,13);
Prepared by RAKHI S HSST CS GHSS Narikkuni Kozhikode , NISHA R HSST CS GHSS Peringom Kannur
b) Q2. Create a table Employee with the following fields and insert at
------------------------------------------------------------------------------ least 5 records into the table except the column Gross_pay and DA.
| Roll_No | Name | Batch | Mark1 | Mark2 | Mark3 | Total | Emp_code Integer Primary key
----------------------------------------------------------------------------- Emp_nameVarchar (20)
| 102 | Allu | Commerce | 23 | 12 | 15 | 50 | Designation Varchar (25)
| 105 | Akku | Commerce | 90 | 88 | 66 | 244 | Department Varchar (25)
----------------------------------------------------------------------------- Basic Decimal (10,2)
c) DA Decimal (10,2)
------------------ Gross_pay Decimal (10,2)
| Name | Total | a) Update DA with 75% of Basic.
------------------ b) Display the details of employees in Purchase, Sales and HR
| Allu | 50 | departments.
| Appu | 48 | c) Update the Gross_pay with the sum of Basic and DA.
------------------ d) Display the details of employee with gross pay below 10000.
d)Empty set.
e)
Query OK, 2 rows affected SQL Statement:
-----------------------------------------------------------------------------
Query for creating Employee table
| Roll_No | Name | Batch | Mark1 | Mark2 | Mark3 | Total |
CREATE TABLE Employee(Emp_Code INT PRIMARY KEY ,
-----------------------------------------------------------------------------
Emp_Name VARCHAR(20),Designation VARCHAR(25), Dept
| 101 | Aju | Science | 89 | 78 | 56 | 223 |
VARCHAR(25),BP DEC(10,2),DA DEC(10,2),Gross DEC(10,2));
| 103 | Ammu | Humanities | 90 | 100 | 100 | 290 |
Inserting values into Employee table
| 105 | Akku | Commerce | 90 | 88 | 66 | 244 |
INSERT INTO Employee(Emp_Code,Emp_Name,Designation,Dept,BP)
-----------------------------------------------------------------------------
VALUES (111,’Aju’,Manager’,’Sales’,25000.00),
(222,’Allu’,’Clerk’,’Purchase’,15000.00),
(333,’Achu’,’Manager’,’HR’,50000.00),
(444,’Akku’,’Clerk’,’Sales’,10000.00),
(555,’Ammu’,’Manager’,’Production’,55000.00);
a) UPDATE Employee SET DA=BP*75/100;
b) SELECT * FROM Employee WHERE Dept
IN(‘Purchase’,’Sales’,’HR’);
c) UPDATE Employee SET Gorss=BP+DA;
d) SELECT * FROM Employee WHERE Gross < 10000;
Prepared by RAKHI S HSST CS GHSS Narikkuni Kozhikode , NISHA R HSST CS GHSS Peringom Kannur
c)
OUTPUT: Query OK, 5 rows affected
Select * from Employee; -----------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------- | Emp_Code | Emp_Name | Designation | Dept | BP | DA | Gross |
| Emp_Code | Emp_Name | Designation | Dept | BP | DA | Gross | -----------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------- | 111 | Aju | Manager | Sales | 25000.00|8750.00 |43750.00 |
| 111 | Aju | Manager | Sales | 25000.00| NULL | NULL | | 222 | Allu | Clerk | Purchase |15000.00| 11250.00 |26250.00|
| 222 | Allu | Clerk | Purchase |15000.00| NULL | NULL | | 333 | Achu | Manager | HR |50000.00| 37500,00|87500.00 |
| 333 | Achu | Manager | HR |50000.00| NULL | NULL | | 444 | Akku | Clerk | Sales |10000.00 | 7500.00| 17500.00|
| 444 | Akku | Clerk | Sales |10000.00 NULL | NULL | | 555 | Ammu|Manager | Production| 55000.00|41250.00|96250.00|
| 555 | Ammu|Manager | Production| 55000.00 | NULL | NULL | -----------------------------------------------------------------------------------------
a) d)
----------------------------------------------------------------------------------------- Empty set.
| Emp_Code | Emp_Name | Designation | Dept | BP | DA | Gross |
-----------------------------------------------------------------------------------------
| 111 | Aju | Manager | Sales | 25000.00|8750.00 | NULL | Q3)Create a table Stock, which stores daily sales of items in a shop,
| 222 | Allu | Clerk | Purchase |15000.00| 11250.00 | NULL | with the following fields and insert at least 5 records into the table.
| 333 | Achu | Manager | HR |50000.00| 37500,00| NULL | Item_code Integer Primary key
| 444 | Akku | Clerk | Sales |10000.00 | 7500.00| NULL | Item_name Varchar (20)
| 555 | Ammu|Manager | Production| 55000.00|41250.00| NULL | Manufacturer_Code Varchar (5)
----------------------------------------------------------------------------------------- Qty Integer
b) Unit_Price Decimal (10,2)
----------------------------------------------------------------------------------------- a. Display the item names with stock zero.
| Emp_Code | Emp_Name | Designation | Dept | BP | DA | Gross | b. Display the number of items manufactured by the same manufacturer.
----------------------------------------------------------------------------------------- c. Display the highest price and lowest quantity in the stock.
| 111 | Aju | Manager | Sales | 25000.00|8750.00 | NULL | d. Increase the unit price of all items by 10%.
| 222 | Allu | Clerk | Purchase |15000.00| 11250.00 | NULL | SQL Statement:
| 333 | Achu | Manager | HR |50000.00| 37500,00| NULL | Query for creating Stock table
| 444 | Akku | Clerk | Sales |10000.00 | 7500.00| NULL | create table Stock(Icode INT PRIMARY KEY,Iname
VARCHAR(20) ,Mcode VARCHAR(5),Qty INT,Unit_Price DEC(10,2));
Inserting values into Stock table
insert into Stock values(101,'Bag','Wildc',100,1500);
insert into Stock values(102,'Mobile','Redme',50,25000);
insert into Stock values(103,'Shoes','Crocs',50,5000);
Prepared by RAKHI S HSST CS GHSS Narikkuni Kozhikode , NISHA R HSST CS GHSS Peringom Kannur
insert into Stock values(104,'Cap','USPA',50,1000);
insert into Stock values(105,'Mobile','Redme',50,28000); d)Query OK, 5 rows affected
Select * from Stock; -----------------------------------------------------
a)Select * form Stock where Qty=0; | Icode | Iname | Mcode | Qty | Unit_Price |
b)Select Mcode,count(Mcode) from Stock group by Mcode; -----------------------------------------------------
c)select max(Unit_price),min(Qty)from Stock; | 101 | Bag | Wildc | 100 | 1650.00 |
d)update Stock set Unit_price=Unit_price+Unit_price*10/100; | 102 | Mobile | Redme | 50 | 27500.00 |
OUTPUT: | 103 | Shoes | Crocs | 50 | 5500.00 |
select * from Stock; | 104 | Cap | USPA | 50 | 1100.00 |
--------------------------------------------------------- | 105 | Mobile | Redme | 75 | 30800.00 |
| Icode | Iname | Mcode | Qty | Unit_Price |
---------------------------------------------------------
| 101 | Bag | Wildc | 100 | 1500.00 | Q4)Create a table Book with the following fields and insert at least 5
| 102 | Mobile | Redme | 50 | 25000.00 | records into the table.
| 103 | Shoes | Crocs | 50 | 5000.00 | Book_ID Integer Primary key
| 104 | Cap | USPA | 50 | 1000.00 | Book_Name Varchar (20)
| 105 | Mobile | Redme | 50 | 28000.00 | Author_Name Varchar (25)
--------------------------------------------------------- Pub_Name Varchar (25)
a)Empty set Price Decimal (10,2)
b) a)Display the details of books with price 100 or more.
------------------------------- b)Display the Name of all books published by SCERT.
| Mcode | count(Mcode) | c)Increase the price of the books by 10% which are published by SCERT.
------------------------------- d)List the details of books with the title containing the word
| Crocs | 1 | "Programming" at the end.
| Redme | 2 | SQL Statement:
| USPA | 1 |
Query for creating Book table
| Wildc | 1 |
create table Book(B_ID INT PRIMARY KEY , B_Name
-------------------------------
VARCHAR(20) , Author VARCHAR(25) ,Pub_Name VARCHAR(25) ,
c)
Price DEC(10,2));
-------------------------------------
Inserting values into Book table
| max(Unit_price) | min(Qty) |
insert into Book
-------------------------------------
values(101,'ComputerApplication','Dr.Lajish','SCERT',125);
| 28000.00 | 50 |
insert into Book values(102,'Compiler Design','Santhanu','PHI',300);
-------------------------------------
Prepared by RAKHI S HSST CS GHSS Narikkuni Kozhikode , NISHA R HSST CS GHSS Peringom Kannur
insert into Book b)
values(103,'Computer Science','Madhu VT','SCERT',110); -----------------------------
insert into Book | B_Name |
values(104,'System Programming','Dhananjay','McGraw-Hill',800); -----------------------------
insert into Book | Computer Application |
values(105,'Computer Programming in C','Rajaraman','PHI',600); | Computer Science |
select * from Book; -----------------------------
a)select * from Book where Price>=100; c)
b)select B_Name from Book where Pub_Name='SCERT'; Query OK, 2 rows affected
c) update Book set Price=Price+Price*10/100 where
Pub_Name='SCERT'; d)
d)select * from Book where B_Name LiKE '%Programming'; -----------------------------------------------------------------------------------
| B_ID | B_Name | Author | Pub_Name | Price |
OUTPUT: -----------------------------------------------------------------------------------
Select * from Book; | 104 | System Programming | Dhananjay | McGraw-Hill | 800.00 |
----------------------------------------------------------------------------------- | 105 | Computer Programming | Rajaraman | PHI | 600.00 |
| B_ID | B_Name | Author | Pub_Name | Price | ------------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
| 101 | Computer Application | Dr.Lajish | SCERT | 125.00 |
| 102 | Compiler Design | Santhanu | PHI | 300.00 |
| 103 | Computer Science | Madhu VT | SCERT | 110.00 |
| 104 | System Programming | Dhananjay | McGraw-Hill | 800.00 |
| 105 | Computer Programming | Rajaraman | PHI | 600.00 |
a)
select * from Book where Price>=100;
-----------------------------------------------------------------------------------
| B_ID | B_Name | Author | Pub_Name | Price |
-----------------------------------------------------------------------------------
| 101 | Computer Application | Dr.Lajish | SCERT | 125.00 |
| 102 | Compiler Design | Santhanu | PHI | 300.00 |
| 103 | Computer Science | Madhu VT | SCERT | 110.00 |
| 104 | System Programming | Dhananjay | McGraw-Hill | 800.00 |
| 105 | Computer Programming | Rajaraman | PHI | 600.00 |
-----------------------------------------------------------------------------------
Prepared by RAKHI S HSST CS GHSS Narikkuni Kozhikode , NISHA R HSST CS GHSS Peringom Kannur