The document outlines three lab exercises focusing on MySQL connectivity using Python. Each lab involves creating a database, defining tables with specific columns, inserting records, and performing various operations such as retrieval, updates, and calculations. The exercises cover inventory management, library management, and order tracking functionalities.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0 ratings0% found this document useful (0 votes)
11 views
PYTHON MYSQL CONNECTIVITY LAB WORK
The document outlines three lab exercises focusing on MySQL connectivity using Python. Each lab involves creating a database, defining tables with specific columns, inserting records, and performing various operations such as retrieval, updates, and calculations. The exercises cover inventory management, library management, and order tracking functionalities.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3
PYTHON MYSQL CONNECTIVITY LAB WORK-2
Write a MySQL connectivity program in Python by importing the
MySQL module to perform the following operations:
a. Create a database named inventory.
b. Create a table PRODUCTS with the following specifications – PRODUCT_ID integer, PRODUCT_NAME varchar(50), CATEGORY varchar(30), PRICE decimal(10, 2), STOCK integer. c. Insert five product records into the PRODUCTS table. d. Display all the product records from the PRODUCTS table using fetchall(). e. Search for product details using PRODUCT_ID and display the record using fetchone(). If the record is not present, display an appropriate message. f. Update the STOCK of a product by 10 where the PRODUCT_ID is 3 and display the product details after the update operation. g. Delete a product using the PRODUCT_ID of the product and display the contents of the table after deletion. If the product PRODUCT_ID is not present in the database, display an appropriate message. h. Display the details of the first three products from the database using fetchmany(). PYTHON MYSQL CONNECTIVITY LAB WORK-3
Write a MySQL connectivity program in Python by importing the
MySQL module to perform the following operations:
1. Create a database named LibraryDB.
2. In the LibraryDB database, create a table named BOOKS with the following columns:
o BOOK_ID - integer, primary key
o TITLE - varchar(50) o AUTHOR - varchar(30) o GENRE - varchar(20) o PRICE - decimal(8, 2) o AVAILABILITY - integer (1 for available, 0 for not available)
3. Insert five book records into the BOOKS table.
4. Retrieve and display all records from the BOOKS table. 5. Update the AVAILABILITY of a book with BOOK_ID = 3 to mark it as checked out (set AVAILABILITY to 0).Display the updated details of the book. 6. Prompt the user to enter a GENRE. Retrieve and display all books in the specified genre. If no books are found, display "No books found in [GENRE]." 7. Calculate and display the average price of all books in the BOOKS table. 8. Display details of all available books. 9. Find and display the details of the most expensive book in the library. Display its BOOK_ID, TITLE, AUTHOR, GENRE, and PRICE. PYTHON MYSQL CONNECTIVITY LAB WORK-4
Write a MySQL connectivity program in Python by importing the
MySQL module to perform the following operations:
1. Create a database named OnlineStoreDB.
2. Create a table named ORDERS with the following columns:
3. Insert seven order records into the ORDERS table
4. Prompt the user to enter a CUSTOMER_ID. Retrieve and display all orders for the customer with that CUSTOMER_ID. 5. Calculate the total amount spent by each customer based on PRICE and QUANTITY. Display each CUSTOMER_ID, PRODUCT, QUANTITY, PRICE, and the calculated total spending for each order. 6. Find products with a total quantity ordered above a certain threshold (e.g., 50) .Display each PRODUCT and its total quantity ordered. 7. Group orders by month and retrieve the number of orders and the total quantity sold for each month from the ORDERS table. Display MONTH, TOTAL_ORDERS, and TOTAL_QUANTITY for each month. 8. Identify products that have been ordered more than 10 times. Display the PRODUCT name and the number of times it has been ordered. 9. Calculate the average quantity of items ordered per order. Display the result as AVERAGE_QUANTITY.