Write Program to perform following tasks (10 Marks)
a. Create a database PRODUCT_SELECTION_DB
b. Set connection with mysql.connector.connect.
c. Create a table PRODUCT _SELECTION in database PRODUCT_SELECTION_DB with
following data PRODUCT_NAME,PRODUCT_PRICE, MANUFACTURER, EXPIRY_DATE.
d. change table structure / (add, edit, remove column of a table) at run time
i. add a column address in the PRODUCT_SELECTION table.
ii. execute SQL INSERT statement to create a record into PRODUCT _SELECTION table
iii. run the query to updates all the records having EXPIRY_DATE as 31-Dec-2022 and
increase PRICE of all the PRODUCTS by 10% of PRODUCT_PRICE.
iv. delete all the records from PRODUCT _SELECTION Table where EXPIRY_DATE is
before 31-Dec-2022.
Below are Python programs to accomplish the tasks outlined using the `mysql.connector` module for database interaction and SQL queries:
```python
import mysql.connector
# Establishing connection to MySQL
try:
connection = mysql.connector.connect(
host="your_host",
user="your_username",
password="your_password",
database="PRODUCT_SELECTION_DB"
)
cursor = connection.cursor()
# Creating a table PRODUCT_SELECTION in database PRODUCT_SELECTION_DB
create_table_query = """
CREATE TABLE IF NOT EXISTS PRODUCT_SELECTION (
PRODUCT_ID INT AUTO_INCREMENT PRIMARY KEY,
PRODUCT_NAME VARCHAR(255),
PRODUCT_PRICE FLOAT,
MANUFACTURER VARCHAR(255),
EXPIRY_DATE DATE
)
"""
cursor.execute(create_table_query)
# Add a column 'address' to the PRODUCT_SELECTION table
add_column_query = "ALTER TABLE PRODUCT_SELECTION ADD COLUMN address VARCHAR(255)"
cursor.execute(add_column_query)
___ ____ ______ __________ _________ ___ _______.
______ ____ _______ ____ ____ ____ _____ ____ _____ __________.
_____ ________ __________ _____ ______ _________ __________ _________ __________ __________ _________ _______.
_________ __________ ______ ____ ____.
_________ _________ ______ _______ ___ ____ ________ ________.
_____ __________ _______ ___ _____ ________.
________ _____ ______ _______ __________ ___ ____ _____.
_________ ____ ________ _______ __________ ______ ___ _______ ___ ___ ____.
_______ ________ __________ ________ ____ __________ ___ _____.
____ ___ ______ _______ __________ ______ _______ ___ _____ _____ ____.
____ ________ _____ ___ ______ _______.
________ __________ ____ __________ ____ ____ ___ _________ ______ _____.
_______ ________ ______ _______ _____.
___ __________ _________ _____ _____ ____ ________ _______ __________ __________ _______.
_____ _______ _____ __________ ___ __________ ________ ________ ____.
______ ___ ______ ____ ______ ___ ___ ______.
____ _____ ______ ______ ______ ____ __________ ______ ________ _____ ___.
__________ _____ __________ ________ ________ _______ _____ _____ ________ ____ ________ ____.
__________ _____ ____ _________ _______ ____ ________ ____ __________ ________ ________.
_______ __________ _________ _______ ________ _____.
___ ___ ______ ____ _______ __________ _____ __________ __________ ________ ___.
_________ __________ _________ __________ _______ ______ _______.
__________ ________ ______ _______ _______ _______ ________ ________ ________ _______.
___ ________ _____ ______ _____ ___ ____ _____ __________ _____ ___ _______.
________ ______ _______ __________ ___ ______ _________ ___.
__________ __________ ___ ____ _____ ____ _________ ______ ___ _____ ___.
________ _______ ________ _______ ____.
_______ ____ ______ ___ _________.
______ ___ ______ __________ ____ _________ _______ __________ _________ _______ ______.
______ __________ _______ ______ _______.
____ ____ ____ _____ _____ ___.
______ __________ __________ ______ ___ ___.
- Solved Assignments
- Study Notes
- Guess Papers
- Question Papers
✓ Unlock up to 60% of the answer
✓ No payment required