Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4242150
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T03:24:13+00:00 2026-05-21T03:24:13+00:00

I’m a bit confused about the entity relationship diagram for my application. So far

  • 0

I’m a bit confused about the entity relationship diagram for my application.

So far I have made tables for Product,Customer,Category

Should I make a table for UserAccounts that holds the id and password for the Customer or directly place the the id and password in the Customer table?

Secondly, each customer will have his own cart. So I have made a CartItem table

CartItemId,
ProductId,
CategoryId,
Description,
UnitPrice,
TotalPrice

But this table is not associating a customer with the cartItem in the shoppingcart. So Should i add the CustomerId here also?

Is there a need for Description and unit price, because those are already defined in the Product Table?

and for Cart Table,
CartId,
CartItemId,
CustomerId

I need to clear up a few things, before I find any mistakes in my application.

DDL:

   CREATE DATABASE ShoppingCart

   Create Table Customer(
   CustomerId int PRIMARY KEY,
   Firstname varchar(50),
   Lastname varchar(50),
   Address varchar(50),
   City varchar(50),
   State varchar(50),
   Country varchar(50),
   Mobile varchar(50),
   Phone varchar(50),
   Email varchar(50)
   )

   Create Table UserAccount(
   UserName varchar(50),
   PasswordHash varchar(50)
   )

   Create Table Category(
   CategoryId int PRIMARY KEY,
   CategoryName varchar(50),
   CategoryDescription varchar(50),
   CategoryImage varchar(50)
   )

   Create Table Products(
   ProductId int PRIMARY KEY,
   ProductName varchar(50),
   Description varchar(50),
   CategoryId int,
   UnitPrice money,
   DateAdded datetime,
   thumn varchar(50),

   CONSTRAINT fk_CategoryId FOREIGN KEY (CategoryId)
   REFERENCES Category(CategoryId)
   )



Create Table CartItem(
CartItemId int,
ProductId int,
CategoryId int,
Description varchar(50),
UnitPrice money,
TotalPrice money,

PRIMARY KEY (CartItemId),
CONSTRAINT fk_ProductId FOREIGN KEY (ProductId)
REFERENCES Products(ProductId),

CONSTRAINT fk_CartItem_CategoryId FOREIGN KEY (CategoryId)
REFERENCES Category(CategoryId)

)

Create Table Cart(
CartId int,
CartItemId int,
ProductId int,
CategoryId int,
Description varchar(50),
UnitPrice money,
TotalPrice money,

PRIMARY KEY (CartId),

CONSTRAINT fk_CartItemId FOREIGN KEY (CartItemId)
REFERENCES CartItem(CartItemId),

CONSTRAINT fk_CartItem_CategoryId FOREIGN KEY (CategoryId)
REFERENCES Category(CategoryId),

PRIMARY KEY (ProductId),
CONSTRAINT fk_CartItemId FOREIGN KEY (ProductId)
REFERENCES CProducts(productId)

)
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T03:24:14+00:00Added an answer on May 21, 2026 at 3:24 am

    #1 Do not store the password – store a salted hash.

    Do not make the customer Id in the cart item table if it’s already obtained through going through Cart table.

    Right now, I think you are confused with having a Cart and CartItem table which are nearly identical.

    UserAccount appears to be orphaned. It needs to be either in the Customer table or somehow linked.

    I would drop CategoryId, Description, UnitPrice and TotalPrice from CartItem (since they are in Product) unless products are customized into the shopping cart for each customer. You also run the risk of letting a user check out with a product at an old price (unless you treat carts as quotes, which is a whole other business domain).

    A CartItem needs a way to get to its Cart or Customer.

    Here’s what I would do:

    Category (CategoryID (PK), etc.)
    
    Customer (CustomerID (PK), etc.)
    
    Product (ProductID (PK), CategoryID (FK), etc)
    
    Cart (CartID (PK), CustomerID (FK), ProductID(FK), Quantity)
    

    When a cart becomes an order, typically an order detail or invoice detail table will lock in the price, and perhaps the name of the product, and the cart will be emptied for a custoemr. A lot of this depends on further business needs.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.