Skip to content

Database Tables for Assignment 2

The eCommerce application in your assignment 2 should include the following core tables:

Table NameDescription
usersStores user account information for both customers and administrators.
categoriesOrganizes products into logical groups (e.g., Electronics, Books, Clothing).
productsContains all product information including name, description, price, and image reference.
product_imagesStores file paths or URLs for uploaded product images (supporting multiple images per product).
ordersRecords completed purchases after checkout.
order_itemsStores details of each product within an order.

ColumnTypeConstraintsDescription
idINTPRIMARY KEY, AUTO_INCREMENTUnique user ID
first_nameVARCHAR(100)NOT NULLUser’s first name
last_nameVARCHAR(100)NOT NULLUser’s last name
usernameVARCHAR(50)UNIQUE, NOT NULLUser’s login name
emailVARCHAR(100)UNIQUE, NOT NULLUser’s email address
password_hashVARCHAR(255)NOT NULLHashed password (bcrypt)
roleENUM(‘admin’, ‘customer’)DEFAULT ‘customer’Defines user role
created_atDATETIMEDEFAULT CURRENT_TIMESTAMPAccount creation date
updated_atDATETIMEON UPDATE CURRENT_TIMESTAMPLast profile update

ColumnTypeConstraintsDescription
idINTPRIMARY KEY, AUTO_INCREMENTCategory ID
nameVARCHAR(100)UNIQUE, NOT NULLCategory name
descriptionTEXTNULLCategory description
created_atDATETIMEDEFAULT CURRENT_TIMESTAMPCreation timestamp

ColumnTypeConstraintsDescription
idINTPRIMARY KEY, AUTO_INCREMENTProduct ID
category_idINTFOREIGN KEY → categories(id)Category this product belongs to
nameVARCHAR(100)NOT NULLProduct name
descriptionTEXTNULLProduct details
priceDECIMAL(10,2)NOT NULLProduct price
stock_quantityINTDEFAULT 0Units available
created_atDATETIMEDEFAULT CURRENT_TIMESTAMPCreation date
updated_atDATETIMEON UPDATE CURRENT_TIMESTAMPLast update date

ColumnTypeConstraintsDescription
idINTPRIMARY KEY, AUTO_INCREMENTImage ID
product_idINTFOREIGN KEY → products(id)Associated product
file_pathVARCHAR(255)NOT NULLPath or filename of uploaded image
is_primaryBOOLEANDEFAULT FALSEMarks main display image

ColumnTypeConstraintsDescription
idINTPRIMARY KEY, AUTO_INCREMENTOrder ID
user_idINTFOREIGN KEY → users(id)Customer who placed the order
total_amountDECIMAL(10,2)NOT NULLTotal price of order
statusVARCHAR(50)DEFAULT ‘Pending’Order status (Pending, Shipped, Completed, Cancelled)
created_atDATETIMEDEFAULT CURRENT_TIMESTAMPOrder creation date

ColumnTypeConstraintsDescription
idINTPRIMARY KEY, AUTO_INCREMENTOrder item ID
order_idINTFOREIGN KEY → orders(id)Associated order
product_idINTFOREIGN KEY → products(id)Purchased product
quantityINTNOT NULLQuantity purchased
unit_priceDECIMAL(10,2)NOT NULLPrice per unit at checkout