Class 12 CS Practical Exercises - 2024 SQL
Class 12 CS Practical Exercises - 2024 SQL
NO:
DATE:
CREATING A PYTHON PROGRAM TO INTEGRATE MYSQL WITH PYTHON
(CREATING DATABASE AND TABLE)
AIM:
To write a Python Program to integrate MYSQL with Python to create Database and Table
to store the details of employees.
Source Code:
Result:
Thus, the above Python program has been executed and the output is verified
successfully.
Sample Output:
*******************************************************************************************************
EX.NO:
DATE:
CREATING A PYTHON PROGRAM TO INTEGRATE MYSQL WITH PYTHON
(INSERTING RECORDS AND DISPLAYING RECORDS)
AIM:
SOURCE CODE:
Result:
Thus, the above Python program has been executed and the output is verified
successfully.
SAMPLE OUTPUT:
***************************************************************************************************************************** *************************************************
EX.NO:
DATE:
CREATING A PYTHON PROGRAM TO INTEGRATE MYSQL WITH PYTHON
(SEARCHING AND DISPLAYING RECORDS)
AIM:
To write a Python Program to integrate MYSQL with Python to search an Employee using
EMPID and display the record if present in already existing table EMP, if not display the
appropriate message.
SOURCE CODE:
Result:
Thus, the above Python program has been executed and the output is verified
successfully.
SAMPLE OUTPUT:
To write a Python Program to integrate MYSQL with Python to search an Employee using
EMPID and update the Salary of an employee if present in already existing table EMP,
if not display the appropriate message.
SOURCE CODE:
Result:
Thus, the above Python program has been executed and the output is verified
successfully.
SAMPLE OUTPUT:
**************************************************************************************************************************************************
SQL PRACTICAL - 1
Ex.No:
DATE:
AIM:
To write Queries for the following Questions based on the given table:
Sol:
(e) Write a Query to List all the tables that exists in the current database.
Sol:
mysql> SHOW TABLES;
Output:
SQL PRACTICAL - 2
Ex.No:
DATE:
AIM:
To write Queries for the following Questions based on the given table:
(a) Write a Query to insert all the rows of above table into Info table.
Sol:
INSERT INTO STU VALUES (1,'Arun','M', 24,'COMPUTER','1997-01-10', 120);
(b) Write a Query to display all the details of the Employees from the above table 'STU'.
Sol:
Output:
Output:
********************************************************************************************
Ex.No: SQL PRACTICAL - 3
DATE:
AIM:
To write Queries for the following Questions based on the given table:
Output:
(b) Write a Query to list name of the students whose ages are between 18 to 20.
Sol:
mysql> SELECT NAME FROM STU WHERE AGE BETWEEN 18 AND 20;
Output:
(c) Write a Query to display the name of the students whose name is starting with 'A'.
Sol:
Output:
(d) Write a query to list the names of those students whose name have second alphabet 'n' in their
names.
Sol:
********************************************************************************************************
Ex.No: SQL PRACTICAL - 4
DATE:
AIM:
To write Queries for the following Questions based on the given table:
(b) Write a Query to change the fess of Student to 170 whose Roll number is 1, if the existing fess
is less than 130.
Sol:
Output(After Update):
(c) Write a Query to add a new column Area of type varchar in table STU.
Sol:
mysql> ALTER TABLE STU ADD AREA VARCHAR(20);
Output:
(d) Write a Query to Display Name of all students whose Area Contains NULL.
Sol:
mysql> SELECT NAME FROM STU WHERE AREA IS NULL;
Output:
(e) Write a Query to delete Area Column from the table STU.
Sol:
mysql> ALTER TABLE STU DROP AREA;
Output:
Sol:
mysql> DROP TABLE STU;
Output:
*******************************************************************************************
Ex.No: SQL PRACTICAL - 4
DATE:
AIM:
To write Queries for the following Questions based on the given table:
TABLE: STOCK
Pno Pname Dcode Qty UnitPrice StockDate
5005 Ball point pen 102 100 10 2021-03-31
5003 Gel pen premium 102 150 15 2021-01-01
5002 Pencil 101 125 4 2021-02-18
5006 Scale 101 200 6 2020-01-01
5001 Eraser 102 210 3 2020-03-19
5004 Sharpner 102 60 5 2020-12-09
5009 Gel pen classic 103 160 8 2022-01-19
TABLE: DEALERS
Dcode Dname
101 Sakthi Stationaries
103 Classic Stationaries
102 Indian Book House
(a) To display the total Unit price of all the products whose Dcode as 102.
Sol:
mysql> SELECT SUM(UNITPRICE) FROM STOCK WHERE DCODE=102;
(b) To display details of all products in the stock table in descending order of Stock date.
Sol:
(c) To display maximum unit price of products for each dealer individually as per dcode
from the table Stock.
Sol:
(d) To display the Pname and Dname from table stock and dealers.
Sol:
mysql> SELECT PNAME,DNAME FROM STOCK S,DEALERS D WHERE S.DCODE=D.DCODE;
*************************************************************************************************