patternsqlMinor
E-commerce database design
Viewed 0 times
databasedesigncommerce
Problem
I am new to database design but am fairly familiar with SQL and its syntax. I want to create a database for an e-commerce website that will sell a single product type such as a shirt. They could be different sizes, colors, and design. I formulated list of information I thought would be necessary to collect from a visitor and are included in the tables I made.
Right now I have tables being:
The tables I created:
``
Right now I have tables being:
Products
Customer
Credit_Card_Details
Order_Details
State_tax
Shopping_Cart
Purchase_history
Shipping type
The tables I created:
``
CREATE TABLE shipping_type
(
type_of_shipping VARCHAR(30) NOT NULL DEFAULT '',
price DOUBLE(6, 2) NOT NULL,
aprox_delivery INT(11) NOT NULL,
PRIMARY KEY (type_of_shipping)
)
engine=innodb
DEFAULT charset=latin1;
CREATE TABLE shopping_cart
(
shopping_cart_id INT(11) UNSIGNED NOT NULL auto_increment,
inventory_id VARCHAR(11) NOT NULL DEFAULT '',
price DOUBLE(6, 2) NOT NULL,
date DATE NOT NULL,
user_id VARCHAR(30) NOT NULL DEFAULT '',
quantity INT(11) NOT NULL,
PRIMARY KEY (shopping_cart_id)
)
engine=innodb
DEFAULT charset=latin1;
CREATE TABLE state_tax
(
state_name VARCHAR(11) NOT NULL DEFAULT '',
sales_tax_rate DOUBLE(6, 2) NOT NULL,
PRIMARY KEY (state_name)
)
engine=innodb
DEFAULT charset=latin1;
CREATE TABLE purchase_history
(
user_id VARCHAR(30) NOT NULL DEFAULT '',
inventory_id INT(11) NOT NULL,
date_ordered DATE NOT NULL,
order_id INT(11) NOT NULL,
quantity INT(11) NOT NULL,
price DOUBLE(6, 2) NOT NULL,
PRIMARY KEY (user_id)
)
engine=innodb
DEFAULT charset=latin1;
CREATE TABLE products
(
inventory_id INT(11) UNSIGNED NOT NULL auto_increment,
shirt_name VARCHAR(50) NOT NULL DEFAULT '',
shirt_size VARCHAR(30) NOT NULL DEFAULT '',
shirt_color INT(11) NOT NULL,
price`Solution
-
Never assume that you're only going to have one product. That will end up being a limiting factor of your design and can cause you a lot of pain later down the line and rules out any kind of code re-usability. Make your products table generic enough to handle any kind of product. Create color/size attribute tables that you can tie to the product if you need to.
-
What about handling the case where people want to order as a guest or will you rule that out entirely?
-
How will you handle returned items/payment credits, cancelled orders, or an order where the credit card is declined? Are you going to keep history for those?
-
You will probably need more than 1 line for address. Are you going to handle international orders? If so you'll need to allow for non-numerical zip codes and ones that don't tie to a state.
-
If you tie shopping carts to cookies then you can reload someone's shopping cart when they come back based on their cookie's ID.
-
If you're going to keep credit card numbers in the database then you need to be PCI Compliant (https://www.pcisecuritystandards.org/).
Never assume that you're only going to have one product. That will end up being a limiting factor of your design and can cause you a lot of pain later down the line and rules out any kind of code re-usability. Make your products table generic enough to handle any kind of product. Create color/size attribute tables that you can tie to the product if you need to.
-
What about handling the case where people want to order as a guest or will you rule that out entirely?
-
How will you handle returned items/payment credits, cancelled orders, or an order where the credit card is declined? Are you going to keep history for those?
-
You will probably need more than 1 line for address. Are you going to handle international orders? If so you'll need to allow for non-numerical zip codes and ones that don't tie to a state.
-
If you tie shopping carts to cookies then you can reload someone's shopping cart when they come back based on their cookie's ID.
-
If you're going to keep credit card numbers in the database then you need to be PCI Compliant (https://www.pcisecuritystandards.org/).
Context
StackExchange Code Review Q#35204, answer score: 9
Revisions (0)
No revisions yet.