DROP DATABASE IF EXISTS TechStore;
CREATE DATABASE TechStore;

USE TechStore;

CREATE TABLE Users(
    UserID INTEGER PRIMARY_KEY AUTO_INCREMENT,
    Name VARCHAR(32),
    Email VARCHAR(256),
    Password VARCHAR(255)
);

CREATE TABLE Products(
    ProductID INTEGER PRIMARY_KEY AUTO_INCREMENT,
    ProductName VARCHAR(104),
    Price NUMERIC
);

CREATE TABLE Orders(
    OrderID INT PRIMARY KEY AUTO_INCREMENT,
    UserID INT,
    OrderDate DATETIME DEFAULT CURRENT_TIMESTAMP,
    Total DECIMAL(10,2),
    Status VARCHAR(20) DEFAULT 'pending',
    FOREIGN KEY (UserID) REFERENCES Users(UserID)
);

CREATE TABLE OrderItems(
    OrderItemID INT PRIMARY KEY AUTO_INCREMENT,
    OrderID INT,
    ProductID INT,
    Quantity INT,
    Price DECIMAL(10,2),
    FOREIGN KEY (OrderID) REFERENCES Orders(OrderID),
    FOREIGN KEY (ProductID) REFERENCES Products(ProductID)
);