Untitled

mail@pastecode.io avatar
unknown
mysql
a month ago
3.5 kB
1
Indexable
Never
CREATE TABLE `Customers`(
    `id` BIGINT NOT NULL AUTO_INCREMENT PRIMARY KEY,
    `first_name` VARCHAR(255) NOT NULL,
    `last_name` VARCHAR(255) NOT NULL,
    `login` VARCHAR(255) NOT NULL,
    `password` VARCHAR(255) NOT NULL,
    `email` VARCHAR(255) NOT NULL,
    `is_subscribed_on_news` TINYINT(1) NOT NULL,
    `phone_number` VARCHAR(255) NOT NULL
);

CREATE TABLE `Products`(
    `id` BIGINT NOT NULL AUTO_INCREMENT PRIMARY KEY,
    `title` VARCHAR(255) NOT NULL,
    `description` VARCHAR(255) NOT NULL,
    `price` DECIMAL(8, 2) NOT NULL,
    `quantity` INT NOT NULL,
    `vendor_code` VARCHAR(255) NOT NULL
);


CREATE TABLE `Categories`(
    `id` BIGINT NOT NULL AUTO_INCREMENT PRIMARY KEY,
    `title` VARCHAR(255) NOT NULL
);

CREATE TABLE `Payments`(
    `id` BIGINT NOT NULL AUTO_INCREMENT PRIMARY KEY,
    `customer_id` BIGINT NOT NULL,
    `payment_date` DATETIME NOT NULL,
    `payment_method` ENUM('') NOT NULL,
    `total_amount` DECIMAL(8, 2) NOT NULL,
    `is_in_credit` TINYINT(1) NOT NULL,
    FOREIGN KEY(`customer_id`) REFERENCES `Customers`(`id`)
);

CREATE TABLE `Shipments`(
    `id` BIGINT NOT NULL AUTO_INCREMENT PRIMARY KEY,
    `customer_id` BIGINT NOT NULL,
    `shipment_date` DATETIME NOT NULL,
    `address` VARCHAR(255) NOT NULL,
    `city` VARCHAR(255) NOT NULL,
    `state` VARCHAR(255) NOT NULL,
    `country` VARCHAR(255) NOT NULL,
    `zip_code` INT NOT NULL,
    FOREIGN KEY(`customer_id`) REFERENCES `Customers`(`id`)
);

CREATE TABLE `Orders`(
    `id` BIGINT NOT NULL AUTO_INCREMENT PRIMARY KEY,
    `order_date` DATETIME NOT NULL,
    `payment_id` BIGINT NOT NULL,
    `shipment_id` BIGINT NOT NULL,
    `customer_id` BIGINT NOT NULL,
    FOREIGN KEY(`payment_id`) REFERENCES `Payments`(`id`),
    FOREIGN KEY(`shipment_id`) REFERENCES `Shipments`(`id`),
    FOREIGN KEY(`customer_id`) REFERENCES `Customers`(`id`)
);


CREATE TABLE `Orders_Products`(
    `id` BIGINT NOT NULL AUTO_INCREMENT PRIMARY KEY,
    `product_id` BIGINT NOT NULL,
    `order_id` BIGINT NOT NULL,
    `quantity` BIGINT NOT NULL,
    FOREIGN KEY(`product_id`) REFERENCES `Products`(`id`),
    FOREIGN KEY(`order_id`) REFERENCES `Orders`(`id`)
);



CREATE TABLE `Wishlist`(
    `id` BIGINT NOT NULL AUTO_INCREMENT PRIMARY KEY,
    `customer_id` BIGINT NOT NULL,
    `product_id` BIGINT NOT NULL,
    FOREIGN KEY(`customer_id`) REFERENCES `Customers`(`id`),
    FOREIGN KEY(`product_id`) REFERENCES `Products`(`id`)
);

CREATE TABLE `Products_Categories`(
    `id` BIGINT NOT NULL AUTO_INCREMENT PRIMARY KEY,
    `product_id` BIGINT NOT NULL,
    `category_id` BIGINT NOT NULL,
    FOREIGN KEY(`product_id`) REFERENCES `Products`(`id`),
    FOREIGN KEY(`category_id`) REFERENCES `Categories`(`id`)
);

CREATE TABLE `Carts`(
    `id` BIGINT NOT NULL AUTO_INCREMENT PRIMARY KEY,
    `quantity` INT NOT NULL,
    `customer_id` BIGINT NOT NULL,
    `product_id` BIGINT NOT NULL,
    FOREIGN KEY(`customer_id`) REFERENCES `Customers`(`id`),
    FOREIGN KEY(`product_id`) REFERENCES `Products`(`id`)
);


CREATE TABLE `Reviews`(
    `id` BIGINT NOT NULL AUTO_INCREMENT PRIMARY KEY,
    `title` VARCHAR(255) NOT NULL,
    `content` VARCHAR(255) NOT NULL,
    `customer_id` BIGINT NOT NULL,
    `product_id` BIGINT NOT NULL,
    FOREIGN KEY(`customer_id`) REFERENCES `Customers`(`id`),
    FOREIGN KEY(`product_id`) REFERENCES `Products`(`id`)
);
Leave a Comment