0% found this document useful (0 votes)
3 views

Create Table Ban Bang

The document creates several database tables to store information for an ecommerce store including tables for categories, brands, products, customers, stores, staff, orders, order items, and stock quantities.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

Create Table Ban Bang

The document creates several database tables to store information for an ecommerce store including tables for categories, brands, products, customers, stores, staff, orders, order items, and stock quantities.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

CREATE TABLE categories (

category_id INT IDENTITY (1, 1) PRIMARY KEY,


category_name VARCHAR (255) NOT NULL
);

CREATE TABLE brands (


brand_id INT IDENTITY (1, 1) PRIMARY KEY,
brand_name VARCHAR (255) NOT NULL
);

CREATE TABLE products (


product_id INT IDENTITY (1, 1) PRIMARY KEY,
product_name VARCHAR (255) NOT NULL,
brand_id INT NOT NULL,
category_id INT NOT NULL,
model_year SMALLINT NOT NULL,
list_price DECIMAL (10, 2) NOT NULL,
FOREIGN KEY (category_id) REFERENCES categories (category_id) ON DELETE
CASCADE ON UPDATE CASCADE,
FOREIGN KEY (brand_id) REFERENCES brands (brand_id) ON DELETE CASCADE ON
UPDATE CASCADE
);

CREATE TABLE customers (


customer_id INT IDENTITY (1, 1) PRIMARY KEY,
first_name VARCHAR (255) NOT NULL,
last_name VARCHAR (255) NOT NULL,
phone VARCHAR (25),
email VARCHAR (255) NOT NULL,
street VARCHAR (255),
city VARCHAR (50),
state VARCHAR (25),
zip_code VARCHAR (5)
);

CREATE TABLE stores (


store_id INT IDENTITY (1, 1) PRIMARY KEY,
store_name VARCHAR (255) NOT NULL,
phone VARCHAR (25),
email VARCHAR (255),
street VARCHAR (255),
city VARCHAR (255),
state VARCHAR (10),
zip_code VARCHAR (5)
);

CREATE TABLE staffs (


staff_id INT IDENTITY (1, 1) PRIMARY KEY,
first_name VARCHAR (50) NOT NULL,
last_name VARCHAR (50) NOT NULL,
email VARCHAR (255) NOT NULL UNIQUE,
phone VARCHAR (25),
active tinyint NOT NULL,
store_id INT NOT NULL,
manager_id INT,
FOREIGN KEY (store_id) REFERENCES stores (store_id) ON DELETE CASCADE ON
UPDATE CASCADE,
FOREIGN KEY (manager_id) REFERENCES staffs (staff_id) ON DELETE NO ACTION ON
UPDATE NO ACTION
);

CREATE TABLE orders (


order_id INT IDENTITY (1, 1) PRIMARY KEY,
customer_id INT,
order_status tinyint NOT NULL,
-- Order status: 1 = Pending; 2 = Processing; 3 = Rejected; 4 = Completed
order_date DATE NOT NULL,
required_date DATE NOT NULL,
shipped_date DATE,
store_id INT NOT NULL,
staff_id INT NOT NULL,
FOREIGN KEY (customer_id) REFERENCES customers (customer_id) ON DELETE
CASCADE ON UPDATE CASCADE,
FOREIGN KEY (store_id) REFERENCES stores (store_id) ON DELETE CASCADE ON
UPDATE CASCADE,
FOREIGN KEY (staff_id) REFERENCES staffs (staff_id) ON DELETE NO ACTION ON
UPDATE NO ACTION
);

CREATE TABLE order_items (


order_id INT,
item_id INT,
product_id INT NOT NULL,
quantity INT NOT NULL,
list_price DECIMAL (10, 2) NOT NULL,
discount DECIMAL (4, 2) NOT NULL DEFAULT 0,
PRIMARY KEY (order_id, item_id),
FOREIGN KEY (order_id) REFERENCES orders (order_id) ON DELETE CASCADE ON
UPDATE CASCADE,
FOREIGN KEY (product_id) REFERENCES products (product_id) ON DELETE CASCADE
ON UPDATE CASCADE
);

CREATE TABLE stocks (


store_id INT,
product_id INT,
quantity INT,
PRIMARY KEY (store_id, product_id),
FOREIGN KEY (store_id) REFERENCES stores (store_id) ON DELETE CASCADE ON
UPDATE CASCADE,
FOREIGN KEY (product_id) REFERENCES products (product_id) ON DELETE CASCADE
ON UPDATE CASCADE
);

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy