By Abdurrahman Elkhadrawy
Video overview: https://www.youtube.com/watch?v=_VQtaVl0KJI
The Database for E-Commerece website includes all entities necessary to handle placing and storing a customers order info on e-commerce site. As such, included in the database's scope is:
- Products, including basic product information of the product itself
- Customers information, including information of the customer themselves
- Orders, includes information in regards to the order itself
- ordersandproducts, containing the relevant orders with their relevant products for analysis and customer troubleshooting. Functioning like a junction table between the orders and products.
- Payment info, includes information nessarcy for payment transactions like type of payment. Amount that was paid and more.
- shipping, contains shipping information it regards to where their shipping to and who is shipping it and much more!
- promotions, contains promotion information in regards to what the promotion is, for how long will it last and more!
- Review/Ratings, contains review infomration that gives us the rating, what they have to say about the product as well.
Out of scope are elements like customers tracking data like what sites they visit etc. We will be maintaing privacy as much as possible and keeping only the information that customers input on the website itself.
- CRUD operations for the products, customers, orders, payment info, shipping, promotions, and reviews to make sure info is up to date
- Track shipping and payment info to make sure customer complaints are handlded efficiently
- The ability to add a start/end time to a promotion so that you dont accidently run multiple promotions at the same time for different products which you didnt intend for
Recommendations for products based on tracking info won't be supported. The only profile we will have on the user is what the user inputted themselves. Hence were not storing external user data anywhere in our database. Only crucial information about our users will be stored.
Entities are captured in MYSQL tables with the following schema.
The database includes the following entities:
The products table includes:
id, which specifies the unique ID for the product as anINT. This column thus has thePRIMARY KEYconstraint applied. This column also has aAUTO_INCREMENTcontstraint applied so if we insert another product it will increment appropriatelyname, which specifies the name of the product as anVARCHAR. givenVARCHARis appropriate for name fields. ANOT NULLconstraint ensures that every product has a name. AUNIQUEconstraint ensures their are no two products with the same name.type, which specfies the type of product as anVARCHAR. givenVARCHARis appropriate for name fields. ANOT NULLconstraint ensures that every product has a type.categories, which specfies the category of a product as anVARCHAR. givenVARCHARis appropriate for name fields. ANOT NULLconstraint ensures that every product has a category.description, which specfies the description of a product as anTEXT. givenTEXTis appropriate for long strings like paragraphs. ANOT NULLconstraint ensures that every product has a description.pricing, which specfies the price of the product as aDECIMAL.DECIMALis appropirate given prices are usually caculated as decimals and we can fix the precision to 2.CHECKconstraint is also added to make sure we dont add negitive price values. ANOT NULLconstraint ensures that every product has a pricequantity, which specfies the amount of the product avaiable as aINT.INTis appropriate given that quantites usually represent whole numbers not decimals etc.CHECKconstraint is also added to make sure we dont add negitive amount of a product. ANOT NULLconstraint ensures that every product has a amount
The CustomerInfo table includes:
id, which specifies the unique ID for the customer as anINT. This column thus has thePRIMARY KEYconstraint applied. This column also has aAUTO_INCREMENTcontstraint applied so if we insert another customerInfo it will increment appropriatelyUsername, which specfies the username of the customer as aVARCHAR.VARCHARis appropriate for name fields. ANOT NULLconstraint ensures that every username is listed. AUNIQUEconstraint ensures their are no two usernames with the same username.Password, which specfies the password of the customer as aVARCHAR.VARCHARis appropriate for name fields. ANOT NULLconstraint ensures that every password is listed. AUNIQUEconstraint ensures their are no two passwords with the same password.firstname, which specfies the first name of the customer as aVARCHAR.VARCHARis appropriate for name fields. ANOT NULLconstraint ensures that every first name is listed.lastname, which specfies the last name of the customer as aVARCHAR.VARCHARis appropriate for name fields. ANOT NULLconstraint ensures that every last name is listed.phonenumber, which specfies the phone number of the customer as aCHAR.CHARis appropriate for name fields and specfies a certain limit of 15 since phone numbers typically in the U.S. dont go above that. ANOT NULLconstraint ensures that every phone number is listed.
The Orders table includes:
id, which specifies the unique ID for the order as anINT. This column thus has thePRIMARY KEYconstraint applied. This column also has aAUTO_INCREMENTcontstraint applied so if we insert another order it will increment appropriatelytimeSubmitted, which specfies the time the order was placed as aDATETIME.DATETIMEis appropriate for when we want to know when the time and date of the order was placed. ANOT NULLconstraint ensures that every instance of a orders time is listed.customerID, which specfies the customer id as anINT. This column thus has theFOREIGN KEYconstraint applied, referencing theidcolumn in thecustomerInfotable, which ensures each order can be referenced back to thecustomerInfotable.billingID, which specfies theidfor the billing information as aINT. This column thus has theFOREIGN KEYconstraint applied, referencing theidcolumn in thePaymentInfotable, which ensures each order can be referenced back to thePaymentInfotable.shippingID, which specfies theidfor the shipping information as aINT. This column thus has theFOREIGN KEYconstraint applied, referencing theidcolumn in theShippingtable, which ensures each order can be referenced back to theShippingtable.
The OrdersandProducts table includes:
id, which specifies the unique ID for the table as anINT. This column thus has thePRIMARY KEYconstraint applied. This column also has aAUTO_INCREMENTcontstraint applied so if we insert another order/product it will increment appropriatelyorderID, which specifies the order id from the orders table as aINT. This column thus has theFOREIGN KEYconstraint applied, referencing theidcolumn in theOrderstable, which ensures each order can be referenced back to theOrderstable.productID, which specifies the product id from the orders table as aINT. This column thus has theFOREIGN KEYconstraint applied, referencing theidcolumn in theproductstable, which ensures each order can be referenced back to theproductstable.quantityPurchased, which specfies the quanity of the product that was purchased as aINT.INTis appropraite given the quanitys are usually whole numbers. ANOT NULLconstraint ensures that every amount of the quanity purchased is listed.
The PaymentInfo table includes:
id, which specifies the unique ID for the table as anINT. This column thus has thePRIMARY KEYconstraint applied. This column also has aAUTO_INCREMENTcontstraint applied so if we insert another payment it will increment appropriatelycustomerID, which specfies the customer id as anINT. This column thus has theFOREIGN KEYconstraint applied, referencing theidcolumn in thecustomerInfotable, which ensures each order can be referenced back to thecustomerInfotable.paymentType, which specfies the type of payment as aENUM.ENUMis used since their are only so many choices like credit or debit. ANOT NULLconstraint ensures that every payment type is listed.PaymentStatus,which specfies the type of payment as aENUM.ENUMis used since their are only so many choices like approved or declined.ANOT NULLconstraint ensures that every status is listed.PaymentSubmissionTime, which specfies the time the payment was was as aDATETIME.DATETIMEis appropriate for when we want to know when the time and date of the payment was processed. ANOT NULLconstraint ensures that every instance of a payment is listed.orderID, which specifies the order id from the orders table as aINT. This column thus has theFOREIGN KEYconstraint applied, referencing theidcolumn in theOrderstable, which ensures each order can be referenced back to theOrderstable.amountPaid, which specfies the price of the order as aDECIMAL.DECIMALis appropirate given orders are usually caculated as decimals and we can fix the precision to 2. ANOT NULLconstraint ensures that every instance of a payment is listed.
The Shipping table includes:
id, which specifies the unique ID for the table as anINT. This column thus has thePRIMARY KEYconstraint applied. This column also has aAUTO_INCREMENTcontstraint applied so if we insert another shipping info it will increment appropriatelycustomerID, which specfies the customer id as anINT. This column thus has theFOREIGN KEYconstraint applied, referencing theidcolumn in thecustomerInfotable, which ensures each order can be referenced back to thecustomerInfotable.orderID, which specifies the order id from the orders table as aINT. This column thus has theFOREIGN KEYconstraint applied, referencing theidcolumn in theOrderstable, which ensures each order can be referenced back to theOrderstable.shippingAddress, which specfies the address of the package being shipped as aVARCHAR.VARCHARis appropriate for name fields. ANOT NULLconstraint ensures that every address is listed.shippingMethod, which specfies the type of shipping as aENUM.ENUMis used since their are only so many choices like standard or express.ANOT NULLconstraint ensures that every type is listed.shippingCost, which specfies the cost of shipping as aDECIMAL.DECIMALis appropirate given prices are usually caculated as decimals and we can fix the precision to 2. ANOT NULLconstraint ensures that every cost of shipping.carrierName, which specfies the type of carrier as aENUM.ENUMis used since their are only so many choices like UPS,USPS,FEDX.ANOT NULLconstraint ensures that every carrier is listed.trackingID, which is the id of the chosen shipping carrier as aCHAR.CHARis appropriate for name fields and specfies a certain limit. ANOT NULLconstraint ensures that every tracking id is listed.orderStatus, which is the status of the order being shipped as aENUM.ENUMis used since their are only so many choices like pending,delivered,shipped.ANOT NULLconstraint ensures that every status is listed.
The Promotion table includes:
promotion information(start date/end date), with its associated id, discount amount and description
id, which specifies the unique ID for the table as anINT. This column thus has thePRIMARY KEYconstraint applied. This column also has aAUTO_INCREMENTcontstraint applied so if we create another promotion it will increment appropriatelyproductID, which specifies the product id from the orders table as aINT. This column thus has theFOREIGN KEYconstraint applied, referencing theidcolumn in theproductstable, which ensures each order can be referenced back to theproductstable.promoStartDate, which specfies the time the promo starts as aDATETIME.DATETIMEis appropriate for when we want to know when the time/date when the promo starts. ANOT NULLconstraint ensures that every instance of a promotional start is listed.promoEndDate, which specfies the time the promo ends as aDATETIME.DATETIMEis appropriate for when we want to know when the time/date when the promo ends. ANOT NULLconstraint ensures that every instance of a promotional end is listed.discountAmount, which specfies the discount amount as aDECIMAL.DECIMALis appropirate given that when we want to caculate the overall price having them represented as decimals will allow for easier caculation and we can fix the precision to 2.CHECKconstraint is also added to make sure we dont add negitive values or any value we dont intend to add. ANOT NULLconstraint ensures we have a discount amount listed.promoDescription, which specfies the promos description as anTEXT. givenTEXTis appropriate for long strings like paragraphs. ANOT NULLconstraint ensures that every product has a description.
The Reviews table includes:
id, which specifies the unique ID for the table as anINT. This column thus has thePRIMARY KEYconstraint applied. This column also has aAUTO_INCREMENTcontstraint applied so if we add another review it will increment appropriatelyproductID, which specifies the product id from the orders table as aINT. This column thus has theFOREIGN KEYconstraint applied, referencing theidcolumn in theproductstable, which ensures each order can be referenced back to theproductstable.customerId, which specfies the customer id as anINT. This column thus has theFOREIGN KEYconstraint applied, referencing theidcolumn in thecustomerInfotable, which ensures each order can be referenced back to thecustomerInfotable.rating, which specfies the rating of the associated product as aINT.INTis appropriate given that ratings are usually assigned whole numbers to it like 1-5. ANOT NULLconstraint ensures that every review has a rating.ratingDescription, which specfies the ratings description as anTEXT. givenTEXTis appropriate for long strings like paragraphs. ANOT NULLconstraint ensures that every product has a description.
The below entity relationship diagram describes the relationships among the entities in the database.
As detailed by the diagram:
- Each shipment must be associated with exactly one customer, but a customer can have zero or many shipments (one to many relationship)
- Each payment must be associated with exactly one customer, but a customer might have zero or many payments made
- Each order must be associated with one customer, but a cusomter might have zero or many orders made
- Each order must have one payment and one shippment information assocaited with it. Hence a one to one relationship, vice versa
- Regarding the ordersandProducts table this is a many to many relationship since each order can have many products associated with it and each product can have many orders associated with and each row of this junction table can only have one order and one product assocaited with it
- Every product has one or no promotion
- Every product has either one or many reviews, with one or many customers as well
Per the typical queries in queries.sql, it is common for users of the database to access all the customer order information when trying to trouble shoot a issue with a ongoing order for example. For that reason, indexes are created on the orderStatus and customerID column on the Shipping table to speed up the customer search.
Similarly, it is also common practice for a user of the databse to be concerned with viewing how well the product is being recieved or how much of the product is available. As such, an index is created on the quantity column in the products table and rating column on the Reviews table to speed up inventory check up and well recieved products.
- The Current schema assumes that we only what the information that we need at the time of designing the database. For example if the company wants multiple promotions that would require one category not to only have one promotion attached to it but many at the same time. Hence a many to many realtionship would be needed. Like if we had black friday sale and a first time user sale we wouldnt be able to apply both under our current design.
- Only one address can belong with one customer so multiple customers with the same address would have to be supported at the application level
