Untitled

mail@pastecode.io avatar
unknown
plain_text
2 months ago
1.3 kB
1
Indexable
Never
import mysql.connector
from prettytable import PrettyTable
import time

# Database Connection
con = mysql.connector.connect(host='localhost', user='root', passwd='host1234')
cur = con.cursor()

try:
    cur.execute("CREATE DATABASE IF NOT EXISTS Restaurant_Management")
    cur.execute("USE Restaurant_Management")

    # Create Tables
    cur.execute("CREATE TABLE IF NOT EXISTS Menu (ItemID INT AUTO_INCREMENT PRIMARY KEY, ItemName VARCHAR(255), "
                "Category VARCHAR(255), Price INT)")

    cur.execute("CREATE TABLE IF NOT EXISTS Orders (OrderID INT AUTO_INCREMENT PRIMARY KEY, ItemID INT, "
                "CustomerName VARCHAR(255), OrderDate DATE, Quantity INT, Packaging VARCHAR(20), "
                "FOREIGN KEY (ItemID) REFERENCES Menu(ItemID))")

    cur.execute("CREATE TABLE IF NOT EXISTS Customer_Orders_Admin LIKE Orders")
    cur.execute("ALTER TABLE Customer_Orders_Admin ADD COLUMN Status VARCHAR(20) DEFAULT 'Pending'")

    # Insert Sample Data
    cur.execute("INSERT IGNORE INTO Menu VALUES (1, 'Burger', 'Fast Food', 10), "
                "(2, 'Pizza', 'Fast Food', 12), (3, 'Salad', 'Healthy', 8)")

    con.commit()

except mysql.connector.Error as err:
    print(f"Error: {err}")
    con.rollback()
Leave a Comment