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 > Im So Confused about tables

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 06-15-07, 14:54
mletendre mletendre is offline
Registered User
 
Join Date: Jun 2007
Posts: 3
Im So Confused about tables

Ok I just started this project to track orders and allow them to be searched. i am using SQL and created tables for:

Customers
----Name, Address, etc
Items
---each record is a different product
PO numbers
----Just a listing of the POs used

there are a few more but the main idea is I have some orders where a single PO has several items in it. Do I create one table and have a record for each item in the PO with the same PO inseveral records or what?

Any insight would be much appreciated
Reply With Quote
  #2 (permalink)  
Old 06-15-07, 15:07
blindman blindman is offline
World Class Flame Warrior
 
Join Date: Jun 2003
Location: Ohio
Posts: 11,726
You need an intermediary table (PurchaseOrderItems) with ItemID and POID to establish a many-to-many relationship between Items and Purchase Orders.
__________________
If it's not practically useful, then it's practically useless.

blindman
www.chess.com: "sqlblindman"
Reply With Quote
  #3 (permalink)  
Old 06-15-07, 15:20
mletendre mletendre is offline
Registered User
 
Join Date: Jun 2007
Posts: 3
what goes inside

I created identifiers in each table already, ie PoId. What should the new table look like? Can you please give me an example using random days such as po 123 item xyz and item ABC by customer 1, then the same customer orders 3 other items with a new po number.

Thank you so much for the quick response!
Reply With Quote
  #4 (permalink)  
Old 06-15-07, 15:47
healdem healdem is offline
Jaded Developer
 
Join Date: Nov 2004
Location: out on a limb
Posts: 9,246
id expect to see soemhtign like

table customer
customerID
....cusotmer details (eg name, locatiojn, delivery address.....)

products table
productID
...product details (eg description, size, weight etc...)

orders table
orderid
ordernumber 'optional
customerid 'identifes the customer making htis order
...order details (eg order date, delivery date....)

orderdetails
orderid } PK
lineno }
productID 'identifies the product this customer has ordered
...line details (eg quantity orderd, price etc...)
__________________
I'd rather be riding my Versys or my Tiger 800 let alone the Norton
Reply With Quote
  #5 (permalink)  
Old 06-15-07, 16:27
mletendre mletendre is offline
Registered User
 
Join Date: Jun 2007
Posts: 3
Ok im still not quite getting it... My tables are currently:

CustomerTable
----CustomerId (int, key identifier)
----Address
----CustomerName

ProductTable
-----ProductId (int, key, identifier)
------ProductNumber
------ProductDescript

PoTable
----PoId (int, key, identifier)
----PoNumber

So I should make a new table and have them layed out like what? My issue is when a single customer has several different items one one PO. should there be seperate records for this such as:

po 123, customer a, product abc
po 123, customer a, product xyz
po 321. customer b, product abc
po 321, customer b, product bcd

and so on?

I would have thought that there has to be a better way to do this, i cant think of how though.
Reply With Quote
  #6 (permalink)  
Old 06-16-07, 14:31
gvee gvee is offline
www.gvee.co.uk
 
Join Date: Jan 2007
Location: UK
Posts: 10,156
I think you need to define the type of relationship between each entity first.

Your choices are:
One to One
One to Many
Many to Many

Also see: http://r937.com/relational.html
__________________
George
Twitter | Blog
Reply With Quote
  #7 (permalink)  
Old 06-16-07, 16:39
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,524
Quote:
Originally Posted by mletendre
So I should make a new table and have them layed out like what?
yes you should, like this --

Customers
ID primary key
Address
Name

Orders
ID primary key
Number
Customer_ID references Customers (ID)

Products
ID primary key
Number
Descript

OrderProducts
O_ID references Orders (ID)
P_ID references Products (ID)
primary key (O_ID,P_ID)
Qty

notice the nicer table and column names
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #8 (permalink)  
Old 06-18-07, 10:19
bankai bankai is offline
Registered User
 
Join Date: Jun 2007
Location: Sweden
Posts: 5
Thumbs up


you made a funny!
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