0% found this document useful (0 votes)
19 views14 pages

Ass 3

The document describes setting up tables in a database for a boutique management system using Python. It includes: 1) Creating tables for customers, online customers, products, courier companies, employees and purchases. 2) Using Python's Faker library to generate and insert fake data into the tables to seed the database with test data. 3) Creating functions to generate unique IDs and insert random records into the purchases table by selecting random products and adding other fake field values.

Uploaded by

sp22-bse-097
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views14 pages

Ass 3

The document describes setting up tables in a database for a boutique management system using Python. It includes: 1) Creating tables for customers, online customers, products, courier companies, employees and purchases. 2) Using Python's Faker library to generate and insert fake data into the tables to seed the database with test data. 3) Creating functions to generate unique IDs and insert random records into the purchases table by selecting random products and adding other fake field values.

Uploaded by

sp22-bse-097
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 14

BOUTIQUE MANAGEMENT SYSTEM

ASSIGNMENT 3
Project Data Insertion:
CREATE TABLE Customer (
CustomerID INT PRIMARY KEY,
Name VARCHAR(255),
Gender VARCHAR(10),
DateOfBirth DATE,
ContactNumber VARCHAR(15),
Email VARCHAR(100),
RegistrationDate DATE,
PurchaseHistory DATE,
Address VARCHAR(255),
CustomerStatus VARCHAR(255)
);

CREATE TABLE OnlineCustomer (


CustomerID INT PRIMARY KEY,
Username VARCHAR(50),
Password VARCHAR(50),
FOREIGN KEY (CustomerID) REFERENCES Customer(CustomerID)
);

Python faker:

total_customers = 0

online_customers = 0

while total_customers < 200: # Adjust the total number of customers as needed

# Generate a unique CustomerID

customer_id = None

while customer_id is None or cursor.execute(f"SELECT COUNT(*) FROM Customer WHERE CustomerID


= {customer_id}").fetchone()[0] > 0:

customer_id = fake.random_int(min=1000, max=9999)

name = fake.name()

gender = fake.random_element(elements=('Male', 'Female'))

date_of_birth = fake.date_of_birth(minimum_age=18, maximum_age=60)

contact_number = fake.phone_number()[:15] # Truncate to fit within VARCHAR(15)

email = fake.email()

registration_date = fake.date_between(start_date='-365d', end_date='today')

purchase_history = fake.date_between(start_date='-365d', end_date='today')


address = fake.address()

customer_status = fake.random_element(elements=('Walk-In', 'Online'))

# SQL query for Customer table

query_customer = f'''

INSERT INTO Customer (CustomerID, Name, Gender, DateOfBirth, ContactNumber, Email,


RegistrationDate, PurchaseHistory, Address, CustomerStatus)

VALUES ({customer_id}, '{name}', '{gender}', '{date_of_birth}', '{contact_number}', '{email}',


'{registration_date}', '{purchase_history}', '{address}', '{customer_status}')

'''

cursor.execute(query_customer)

total_customers += 1

if customer_status == 'Online' and online_customers < 50:

# SQL query for OnlineCustomer table

username = fake.email()

password = fake.password()

query_online_customer = f'''

INSERT INTO OnlineCustomer (CustomerID, Username, Password)

VALUES ({customer_id}, '{username}', '{password}')

'''

cursor.execute(query_online_customer)

online_customers += 1

CREATE TABLE Products (


productId INT PRIMARY KEY,
name VARCHAR(255) NOT NULL,
size VARCHAR(50),
color VARCHAR(50),
material VARCHAR(100),
category VARCHAR(50)
);

INSERT INTO Products (productId, name, size, color, material, category)


VALUES(6115, '3 piece suit', 'Small', 'Blue', 'Cotton', 'Clothing'),
(6116, '3 piece suit', 'Medium', 'Red', 'Silk', 'Clothing'),
(6117, '3 piece suit', 'Large', 'Black', 'Velvet', 'Clothing'),
(6118, '2 piece suit', 'Small', 'Green', 'Wool', 'Clothing'),
(6119, '2 piece suit', 'Medium', 'White', 'Linen', 'Clothing'),
(6120, '2 piece suit', 'Large', 'Purple', 'Polyester', 'Clothing'),
(6121, 'Kurta', 'Small', 'Yellow', 'Cotton', 'Clothing'),
(6122, 'Kurta', 'Medium', 'Pink', 'Silk', 'Clothing'),
(6123, 'Kurta', 'Large', 'Brown', 'Linen', 'Clothing'),
(6124, 'Dupatta', 'Standard', 'Orange', 'Chiffon', 'Accessories'),
(6125, 'Scarf', 'Small', 'Blue', 'Cashmere', 'Accessories'),
(6126, 'Scarf', 'Medium', 'Red', 'Wool', 'Accessories'),
(6127, 'Scarf', 'Large', 'Green', 'Silk', 'Accessories'),
(6128, 'Bottoms', 'Small', 'Black', 'Denim', 'Clothing'),
(6129, 'Bottoms', 'Medium', 'White', 'Cotton', 'Clothing'),
(6130, 'Bottoms', 'Large', 'Gray', 'Polyester', 'Clothing'),
(6131, 'Shoes', '7', 'Brown', 'Leather', 'Footwear'),
(6132, 'Shoes', '8', 'Black', 'Suede', 'Footwear'),
(6133, 'Shoes', '9', 'White', 'Canvas', 'Footwear'),
(6134, 'Watches', 'Standard', 'Silver', 'Metal', 'Accessories'),
(6135, 'Watches', 'Standard', 'Gold', 'Stainless Steel', 'Accessories'),
(6136, 'Earrings', 'Small', 'Rose Gold', 'Gold', 'Jewelry'),
(6137, 'Earrings', 'Medium', 'Silver', 'Sterling Silver', 'Jewelry'),
(6138, 'Earrings', 'Large', 'Bronze', 'Brass', 'Jewelry'),
(6139, 'Rings', 'Size 5', 'Gold', 'Gold', 'Jewelry'),
(6140, 'Rings', 'Size 6', 'Silver', 'Sterling Silver', 'Jewelry'),
(6141, 'Rings', 'Size 7', 'Rose Gold', 'Rose Gold', 'Jewelry'),
(6142, '2 piece suit', 'Small', 'Purple', 'Silk', 'Clothing'),
(6143, '2 piece suit', 'Medium', 'Black', 'Velvet', 'Clothing'),
(6144, '2 piece suit', 'Large', 'Green', 'Wool', 'Clothing'),
(6145, 'Kurta', 'Small', 'Red', 'Cotton', 'Clothing'),
(6146, 'Kurta', 'Medium', 'Blue', 'Linen', 'Clothing'),
(6147, 'Kurta', 'Large', 'Pink', 'Silk', 'Clothing'),
(6148, 'Dupatta', 'Standard', 'Yellow', 'Chiffon', 'Accessories'),
(6149, 'Dupatta', 'Standard', 'Orange', 'Georgette', 'Accessories'),
(6150, 'Scarf', 'Small', 'Brown', 'Cashmere', 'Accessories'),
(6151, 'Scarf', 'Medium', 'Gray', 'Wool', 'Accessories'),
(6152, 'Scarf', 'Large', 'White', 'Silk', 'Accessories'),
(6153, 'Bottoms', 'Small', 'Beige', 'Denim', 'Clothing'),
(6154, 'Bottoms', 'Medium', 'Khaki', 'Cotton', 'Clothing'),
(6155, 'Bottoms', 'Large', 'Navy', 'Polyester', 'Clothing'),
(6156, 'Shoes', '7', 'Tan', 'Leather', 'Footwear'),
(6157, 'Shoes', '8', 'Blue', 'Suede', 'Footwear'),
(6158, 'Shoes', '9', 'Red', 'Canvas', 'Footwear'),
(6159, 'Watches', 'Standard', 'Black', 'Metal', 'Accessories'),
(6160, 'Watches', 'Standard', 'Rose Gold', 'Stainless Steel', 'Accessories'),
(6161, 'Earrings', 'Small', 'Gold', 'Gold', 'Jewelry'),
(6162, 'Earrings', 'Medium', 'Silver', 'Sterling Silver', 'Jewelry'),
(6163, 'Earrings', 'Large', 'Bronze', 'Brass', 'Jewelry'),
(6164, 'Rings', 'Size 5', 'Rose Gold', 'Gold', 'Jewelry');

CREATE TABLE CourierCompany (


CourierID INT PRIMARY KEY,
CompanyName VARCHAR(100),
ContactInformation VARCHAR(255),
DeliveryTimeEstimates VARCHAR(100)
);
Python faker:
fake = Faker()

courierId = 1001
for _ in range(200): # Adjust the loop range to 200
company_name ='TCS'
contact_information = fake.phone_number()
delivery_time_estimates = fake.random_element(elements=('Same Day', 'Next Day', '2-3
Days', '3-5 Days'))

query = f'''
INSERT INTO CourierCompany (CourierID, CompanyName, ContactInformation,
DeliveryTimeEstimates)
VALUES ({courierId}, '{company_name}', '{contact_information}',
'{delivery_time_estimates}')
'''

courierId += 1

CREATE TABLE Employee (


EmployeeID INT PRIMARY KEY,
Name VARCHAR(255),
Gender VARCHAR(10),
DateOfBirth DATE,
ContactNumber VARCHAR(15),
Email VARCHAR(100),
Position VARCHAR(50),
Salary DECIMAL(10, 2),
HireDate DATE,
Address VARCHAR(255)
);

Python faker:

fake = Faker()

# Common salary for designers, cashiers, and staff

commonsalaryst = fake.pydecimal(left_digits=5, right_digits=2, positive=True, min_value=12000,


max_value=20000)

commonsalaryc = fake.pydecimal(left_digits=5, right_digits=2, positive=True, min_value=30000,


max_value=80000)

commonsalaryd = fake.pydecimal(left_digits=6, right_digits=2, positive=True, min_value=120000,


max_value=200000)

commonsalarym = fake.pydecimal(left_digits=6, right_digits=2, positive=True, min_value=250000,


max_value=400000)

# Counters for each position

manager_count = 0
cashier_count = 0

designer_count = 0

for _ in range(50): # Adjust the loop range to 200

# Generate a unique EmployeeID

employee_id = None

while employee_id is None or cursor.execute(f"SELECT COUNT(*) FROM Employee WHERE EmployeeID


= {employee_id}").fetchone()[0] > 0:

employee_id = fake.random_int(min=1000, max=9999)

name = fake.name()

gender = fake.random_element(elements=('Male', 'Female'))

date_of_birth = fake.date_of_birth(minimum_age=18, maximum_age=60)

contact_number = fake.phone_number()[:15] # Truncate to fit within VARCHAR(15)

email = fake.email()

# Assign positions based on counts

if manager_count < 2:

position = 'Manager'

manager_count += 1

salary = commonsalarym

elif cashier_count < 4:

position = 'Cashier'

cashier_count += 1

salary = commonsalaryc # Use common salary for cashiers

elif designer_count < 3:

position = 'Designer'

designer_count += 1

salary = commonsalaryd # Use common salary for designers

else:

position = 'Staff'
salary = commonsalaryst # Use common salary for staff

hire_date = fake.date_between(start_date='-365d', end_date='today')

address = fake.address()

query = f'''

INSERT INTO Employee (EmployeeID, Name, Gender, DateOfBirth, ContactNumber, Email, Position,
Salary, HireDate, Address)

VALUES ({employee_id}, '{name}', '{gender}', '{date_of_birth}', '{contact_number}', '{email}',


'{position}', {salary}, GETDATE(), '{address}')

CREATE TABLE purchase(


purchaseID INT NOT NULL UNIQUE,
productId INT FOREIGN KEY (productId) REFERENCES Products(productId),
date_of_purchase DATE,
purchase_price money Primary key ,
quantity INT,
qty_rem int ,
supplier VARCHAR(255)

);

Python faker:
if not valid_product_ids:
print("No valid ProductID found in the Products table. Please insert some values
first.")
else:
# Create a Faker instance
fake = Faker()

# Shuffle the valid ProductIDs to ensure random selection without repetition


random.shuffle(valid_product_ids)

# Function to generate a valid PurchaseID


def generate_valid_purchase_id():
while True:
fake_purchase_id = fake.random_int(min=1000, max=9999)
cursor.execute(f"SELECT COUNT(*) FROM Purchase WHERE PurchaseID =
{fake_purchase_id}")
count = cursor.fetchone()[0]
if count == 0:
return fake_purchase_id

# Function to insert data into Purchase table


def insert_fake_purchase():
fake_purchase_id = generate_valid_purchase_id()
fake_product_id = valid_product_ids.pop() # Take ProductID from the shuffled
list
fake_purchase_date = fake.date_this_year()
# Generate a unique fake_purchase_price
while True:
fake_purchase_price = fake.pydecimal(left_digits=5, right_digits=2,
positive=True, min_value=1800.0, max_value=5500.0)
cursor.execute(f"SELECT COUNT(*) FROM Purchase WHERE purchase_price =
{fake_purchase_price}")
count = cursor.fetchone()[0]
if count == 0:
break # Exit the loop if the PurchasePrice is unique

fake_quantity = random.randint(1000, 1500)


fake_quantity_remaining = random.randint(1000, 1500)
fake_supplier = fake.random_element(elements=('Maria.B', 'Sapphire', 'J.',
'Outfitters'))

# Insert fake purchase into Purchase table


insert_purchase_query = f"""
INSERT INTO Purchase (PurchaseID, ProductID, date_of_purchase,
purchase_price, quantity, qty_rem ,supplier)
VALUES ({fake_purchase_id}, {fake_product_id}, '{fake_purchase_date}',
{fake_purchase_price}, {fake_quantity},
{fake_quantity_remaining},'{fake_supplier}')
"""

try:
cursor.execute(insert_purchase_query)
conn.commit()
except pyodbc.Error as e:
print(f"Error inserting purchase data: {e}")
conn.rollback()

# Insert data into Purchase table


total_purchases = 50

for _ in range(total_purchases):
insert_fake_purchase()

# Fetch and display Purchase table data


select_purchase_query = """
SELECT *
FROM Purchase
"""

CREATE TABLE Price (


PriceID INT,
ProductID INT FOREIGN KEY (productId) REFERENCES Products(productId),
purchase_price money FOREIGN KEY (purchase_price) REFERENCES
purchase(purchase_price),
sale_price money primary key
)

Python faker:

# Create a Faker instance


fake = Faker()

def generate_valid_price_id():
while True:
fake_price_id = fake.random_int(min=1000, max=9999)
cursor.execute(f"SELECT COUNT(*) FROM Price WHERE PriceID =
{fake_price_id}")
count = cursor.fetchone()[0]
if count == 0:
return fake_price_id

# Function to insert data into Price table


def insert_fake_price():
fake_price_id = generate_valid_price_id()

# Pop a ProductID from the list


if all_product_ids:
fake_product_id = all_product_ids.pop()

# Fetch the PurchasePrice from the Purchase table based on ProductID


cursor.execute(f"SELECT TOP 1 purchase_price FROM Purchase WHERE
ProductID = {fake_product_id} ORDER BY NEWID()")
purchase_price_row = cursor.fetchone()

if purchase_price_row:
purchase_price = purchase_price_row.purchase_price
fake_sale_price = Decimal(str(round(float(purchase_price) * 1.20,
2))) # Convert to Decimal

# Insert fake price into Price table


insert_price_query = f"""
INSERT INTO Price (PriceID, ProductID, purchase_price,
sale_price)
VALUES ({fake_price_id}, {fake_product_id}, {purchase_price},
{fake_sale_price})
"""

try:
cursor.execute(insert_price_query)
conn.commit()
except pyodbc.Error as e:
print(f"Error inserting price data: {e}")
conn.rollback()
else:
print(f"No PurchasePrice found for ProductID {fake_product_id}.
Skipping insertion.")
else:
print("No more ProductIDs available. Skipping insertion.")

# Insert data into Price table


total_prices = len(all_product_ids)

for _ in range(total_prices):
insert_fake_price()

# Fetch and display Price table data with ProductIDs


select_price_query = """
SELECT p.PriceID, p.ProductID, p.purchase_price, p.sale_price
FROM Price p
CREATE TABLE OnlineOrder (
OrderID INT PRIMARY KEY,
CustomerID INT FOREIGN KEY REFERENCES OnlineCustomer(CustomerID),
OrderDate DATETIME,
ProductID int FOREIGN KEY REFERENCES Products(ProductID),
qty int,
sale_price money FOREIGN KEY REFERENCES Price(sale_price),
DeliveryStatus VARCHAR(50),
CourierID INT FOREIGN KEY REFERENCES CourierCompany(CourierID),
EmployeeID INT FOREIGN KEY REFERENCES Employee(EmployeeID)
);

Python faker:
cursor = conn.cursor()

# Check if there are any valid ProductIDs, CustomerIDs, and EmployeeIDs


cursor.execute("SELECT COUNT(*) FROM Products")
total_products = cursor.fetchone()[0]

cursor.execute("SELECT COUNT(*) FROM OnlineCustomer")


total_customers = cursor.fetchone()[0]

cursor.execute("SELECT COUNT(*) FROM Employee")


total_employees = cursor.fetchone()[0]

if total_products == 0 or total_customers == 0 or total_employees == 0:


print("Please insert some values into Products, OnlineCustomer, and Employee
tables first.")
else:
# Create a Faker instance
fake = Faker()

# Function to generate a valid OrderID


def generate_valid_order_id():
while True:
fake_order_id = fake.random_int(min=1000, max=9999)
cursor.execute(f"SELECT COUNT(*) FROM OnlineOrder WHERE OrderID =
{fake_order_id}")
count = cursor.fetchone()[0]
if count == 0:
return fake_order_id

# Function to insert data into OnlineOrder table


def insert_fake_order():
fake_order_id = generate_valid_order_id()

# Fetch a random ProductID and Quantity from the Purchase table


cursor.execute("SELECT TOP 1 p.ProductID, pr.qty_rem FROM Products p INNER
JOIN Purchase pr ON p.ProductID = pr.ProductID WHERE pr.qty_rem > 0 ORDER BY NEWID()")
purchase_data = cursor.fetchone()

if purchase_data is not None:


fake_product_id, remaining_quantity = purchase_data.ProductID,
purchase_data.qty_rem

# Set the maximum value of the random quantity to the remaining quantity
fake_quantity = random.randint(1, min(remaining_quantity, 7))
# Check if remaining quantity will be less than 0 after the order
if remaining_quantity - fake_quantity < 0:
print(f"Not enough stock for ProductID {fake_product_id} to fulfill
OrderID {fake_order_id}")
return

# Subtract the quantity from the remaining quantity in the Purchase table
cursor.execute(f"UPDATE Purchase SET qty_rem = qty_rem - {fake_quantity}
WHERE ProductID = {fake_product_id}")

# Fetch an existing CustomerID from the OnlineCustomer table


cursor.execute("SELECT TOP 1 CustomerID FROM OnlineCustomer ORDER BY
NEWID()")
fake_customer_id = cursor.fetchone().CustomerID

# Fetch an existing CourierID from the CourierCompany table


cursor.execute("SELECT TOP 1 CourierID FROM CourierCompany ORDER BY
NEWID()")
fake_courier_id = cursor.fetchone().CourierID

# Fetch an existing EmployeeID from the Employee table


cursor.execute("SELECT TOP 1 EmployeeID FROM Employee ORDER BY NEWID()")
fake_employee_id = cursor.fetchone().EmployeeID

# Fetch an existing SalePrice from the Price table


cursor.execute("SELECT TOP 1 sale_price FROM Price ORDER BY NEWID()")
sale_price = cursor.fetchone().sale_price

# Generate a random delivery status


fake_delivery_status = random.choice(['Processing', 'Shipped',
'Delivered'])

# Insert fake order into OnlineOrder table


insert_order_query = f"""
INSERT INTO OnlineOrder (OrderID, CustomerID, OrderDate, ProductID,
qty, sale_price, DeliveryStatus, CourierID, EmployeeID)
VALUES ({fake_order_id}, {fake_customer_id},
'{fake.date_time_between(start_date='-1y', end_date='now')}',
{fake_product_id}, {fake_quantity}, {sale_price},
'{fake_delivery_status}', {fake_courier_id}, {fake_employee_id})
"""

try:
cursor.execute(insert_order_query)
conn.commit()
print(f"Successfully inserted OrderID {fake_order_id} with Quantity
{fake_quantity}")

# Check if the remaining quantity in the Purchase table has reached


zero
if remaining_quantity - fake_quantity == 0:
print(f"Quantity for ProductID {fake_product_id} reached zero in
the Purchase table.")

except pyodbc.Error as e:
print(f"Error inserting order data: {e}")
conn.rollback()
else:
print("No available products for order.")

# Insert data into OnlineOrder table 1000 times


total_orders = 1000

for _ in range(total_orders):
insert_fake_order()

CREATE TABLE Sales (


SaleID INT NOT NULL unique,
ProductID INT,
Quantity INT,
sale_price money FOREIGN KEY REFERENCES Price(sale_price),
SaleDate DATETIME,
CustomerID INT FOREIGN KEY REFERENCES Customer(CustomerID),
FOREIGN KEY (ProductID) REFERENCES Products(ProductID),
EmployeeID INT FOREIGN KEY REFERENCES Employee(EmployeeID)
);

Python faker:

cursor = conn.cursor()

# Check if there are any valid ProductIDs, CustomerIDs, and EmployeeIDs

cursor.execute("SELECT COUNT(*) FROM Products")

total_products = cursor.fetchone()[0]

cursor.execute("SELECT COUNT(*) FROM Customer")

total_customers = cursor.fetchone()[0]

cursor.execute("SELECT COUNT(*) FROM Employee")

total_employees = cursor.fetchone()[0]

if total_products == 0 or total_customers == 0 or total_employees == 0:

print("Please insert some values into Products, Customer, and Employee tables first.")

else:

# Create a Faker instance

fake = Faker()

# Function to generate a valid SaleID

def generate_valid_sale_id():

while True:

fake_sale_id = fake.random_int(min=1000, max=9999)

cursor.execute(f"SELECT COUNT(*) FROM Sales WHERE SaleID = {fake_sale_id}")


count = cursor.fetchone()[0]

if count == 0:

return fake_sale_id

# Function to insert data into Sales table

def insert_fake_sale():

fake_sale_id = generate_valid_sale_id()

# Fetch a random ProductID and Quantity from the Purchase table

cursor.execute("SELECT TOP 1 p.ProductID, pr.qty_rem FROM Products p INNER JOIN Purchase pr


ON p.ProductID = pr.ProductID WHERE pr.qty_rem > 0 ORDER BY NEWID()")

purchase_data = cursor.fetchone()

if purchase_data is not None:

fake_product_id, remaining_quantity = purchase_data.ProductID, purchase_data.qty_rem

# Set the maximum value of the random quantity to the remaining quantity

fake_quantity = random.randint(1, min(remaining_quantity, 7))

# Check if remaining quantity will be less than 0 after the sale

if remaining_quantity - fake_quantity < 0:

print(f"Not enough stock for ProductID {fake_product_id} to fulfill SaleID {fake_sale_id}")

return

# Subtract the quantity from the remaining quantity in the Purchase table

cursor.execute(f"UPDATE Purchase SET qty_rem = qty_rem - {fake_quantity} WHERE ProductID


= {fake_product_id}")

# Fetch an existing CustomerID from the Customer table

cursor.execute("SELECT TOP 1 CustomerID FROM Customer ORDER BY NEWID()")

fake_customer_id = cursor.fetchone().CustomerID

# Fetch an existing EmployeeID from the Employee table

cursor.execute("SELECT TOP 1 EmployeeID FROM Employee ORDER BY NEWID()")

fake_employee_id = cursor.fetchone().EmployeeID
# Fetch an existing SalePrice from the Price table

cursor.execute("SELECT TOP 1 sale_price FROM Price ORDER BY NEWID()")

sale_price = cursor.fetchone().sale_price

# Insert fake sale into Sales table

insert_sale_query = f"""

INSERT INTO Sales (SaleID, ProductID, Quantity, sale_price, SaleDate, CustomerID,


EmployeeID)

VALUES ({fake_sale_id}, {fake_product_id}, {fake_quantity}, {sale_price},

'{fake.date_time_between(start_date='-1d', end_date='now')}',

{fake_customer_id}, {fake_employee_id}

"""

try:

cursor.execute(insert_sale_query)

conn.commit()

print(f"Successfully inserted SaleID {fake_sale_id} with Quantity {fake_quantity}")

# Check if the remaining quantity in the Purchase table has reached zero

if remaining_quantity - fake_quantity == 0:

print(f"Quantity for ProductID {fake_product_id} reached zero in the Purchase table.")

except pyodbc.Error as e:

print(f"Error inserting sale data: {e}")

conn.rollback()

else:

print("No available products for sale.")

You might also like