If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > General > Database Concepts & Design > Database Design

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 10-13-10, 09:49
richardfennah richardfennah is offline
Registered User
 
Join Date: Oct 2010
Posts: 4
Database Design

Hi there!

I am creating a database to hold all the data for a customer portal for a business.

The portal will hold all information about the orders that customers place and the status of the orders.

The business offer different prices to each customer for the products and this has created a bit of a problem in terms of my design for the database.

My current ideas are as follows:

Orders Table (details of each order including the total price for the order)
OrderItems Table (details of what items are included in the order)
Products Table (containing all the details of each product they sell excluding the price of each item)

I now need somewhere to store each customer's price list and still have a link to the Products table.

Does anyone have any thoughts as to how I may achieve this?

Cheers!
Reply With Quote
  #2 (permalink)  
Old 10-13-10, 10:07
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,524
just like OrderItems is a many-to-many table between orders and products, you need CustomerItems to be the many-to-many table between customers and products

then the product_id in the CustomerItems table is your link back to the products table
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #3 (permalink)  
Old 10-13-10, 10:11
richardfennah richardfennah is offline
Registered User
 
Join Date: Oct 2010
Posts: 4
Sorry to be a pain here but could you explain this a bit more to me?

Could you literally explain what columns I should make to store the prices?

Thanks for you help!
Reply With Quote
  #4 (permalink)  
Old 10-13-10, 10:23
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,524
Quote:
Originally Posted by richardfennah View Post
Could you literally explain what columns I should make to store the prices?
sure, no problem

CREATE TABLE CustomerPrices
( cust_id INTEGER NOT NULL
, FOREIGN KEY (cust_id) REFERENCES Customers (id)
, product_id INTEGER NOT NULL
, FOREIGN KEY (product_id) REFERENCES Products (id)
, PRIMARY KEY (cust_id,product_id)
, price DECIMAL(9,2) NOT NULL
);

those are the columns you will need
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #5 (permalink)  
Old 10-13-10, 10:37
richardfennah richardfennah is offline
Registered User
 
Join Date: Oct 2010
Posts: 4
Ok cheers for that.

Now my second question! Sorry!

Say I now want to enter the price for Product1 for Customer1 into that table.

How do I format this?

Thanks for this!
Reply With Quote
  #6 (permalink)  
Old 10-13-10, 10:45
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,524
Code:
INSERT INTO CustomerPrices VALUES ( 1, 1, 9.37 )
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #7 (permalink)  
Old 10-13-10, 11:28
richardfennah richardfennah is offline
Registered User
 
Join Date: Oct 2010
Posts: 4
Brilliant!

Works great, thanks for your help!
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On