Re: Database Design Problem

From: Greg Obleshchuk (greg-n-o-s-p-a-m-_at_ag-s-o-f-t-w-a-r-e.com)
Date: 04/26/04


Date: Tue, 27 Apr 2004 09:53:01 +1000

Hi Daniel,
No you are on the right track.
You have an order table because there is an order and a order it placed on a
certain date and in your case is for a certain customer

You have an orderdetails table because each order can consist of many
details lines. Moving the shipdate to the orderdetails is perfectly normal
because in the real world this happens. I would have thought though looking
at your design that you would lose ProductCategoryID from the Orders table
as this sounds like it relates to a product and should be in the products
table. You should also have a customer and employee table and only include
the key to these tables in the orders table. So something like this

CREATE TABLE [dbo].[Orders] (
 [OrderID] [varchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL ,
 [EmployeeID [INT] NOT NULL ,
 [CustomerID [INT] NOT NULL ,
 [TagID] [int] NULL ,
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[Order Details] (
[SerialNumber] [varchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[OrderID] [varchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL ,
[ProductID] [int] NOT NULL ,
[CustomerPO] [varchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[Quantity] [int] NULL ,
[ShipDate] [datetime] NULL
[Instructions] [varchar] (250) COLLATE SQL_Latin1_General_CP1_CI_AS NULL

) ON [PRIMARY]
GO

You would also have primarykeys on OrderID in ORders and SerialNumber in
Orders Details

Looking at CustomerPO why would you include this in the details table, I am
asumming there is only one purchase order per order

-- 
I hope this helps
--------------------------------
Greg O
Looking for SQL Scripts, Need Help? http://www.SQL-Scripts.com
Document all your databases now.
http://www.ag-software.com/ags_scribe_index.aspx
Crosstab queries from SQL Server.
http://www.ag-software.com/xp_ags_crosstab.aspx
Edit Extended Properties as easy as can be.
http://www.ag-software.com/ags_SSEPE_index.aspx
"Daniel" <dan@spam.com> wrote in message
news:u57D9L#KEHA.2952@TK2MSFTNGP10.phx.gbl...
> Hello,
>
> I have a question on how to map a Order and Order Details relationship.
In
> the Orders table I have an OrderID key and some other customer info (Name,
> Ship Date...).  The Order Details uses OrderID as the key because there is
> one to many relationship with Order.  The problem I am running into is
there
> is another field (Serial) which is a unique to each line item(order
details
> record) for the Order.  When I redesign my Order and Order Details tables,
> the Order table only contains Customer Name and a couple of other details
> (employee).  I had to move ShipDate and couple of other cusotmer details
to
> Order Details because each line item can have different ship date and so
on.
> I am just wondering is it worth having an Order table or maybe I can
create
> one table or map it another way?  Here is the DDL of the two tables:
>
> CREATE TABLE [dbo].[Orders] (
>  [OrderID] [varchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL ,
>  [ProductCatagoryID] [varchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS
> NULL ,
>  [EmployeeName] [varchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
>  [TagID] [int] NULL ,
>  [CustomerName] [varchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
> ) ON [PRIMARY]
> GO
>
> CREATE TABLE [dbo].[Order Details] (
>  [OrderID] [varchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL ,
>  [ProductID] [int] NOT NULL ,
>  [SerialNumber] [varchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
>  [CustomerPO] [varchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
>  [Quantity] [int] NULL ,
>  [ShipDate] [datetime] NULL
>  [Instructions] [varchar] (250) COLLATE SQL_Latin1_General_CP1_CI_AS NULL
> ) ON [PRIMARY]
> GO
>
>
>


Relevant Pages

  • Re: BIG BUG in Deleting detali records
    ... in the database in order to enforce referential integrity. ... when the customer himself is deleted from the master table. ... customerID int identity not null primary key, ...
    (borland.public.delphi.database.ado)
  • Re: writing strings instead of rabish to file using fprintf
    ... > please and help me finding the reason why this rabish is being ... use either int or unsigned ... And similarly with customer number. ... FAQ below. ...
    (comp.lang.c)
  • Re: How to make a Foreing Key?
    ... Supose I have this tables DETAIL, HEADER and ITEMS and I want to add in the ... Should I ADD a field CUSTOMER in the table DETAIL to do that? ...
    (microsoft.public.sqlserver.programming)
  • Re: Table design teaser
    ... Why do STAFF and CUSTOMER have to be separate tables? ... > CUSTOMER (ID int pk, ... STAFF_CUSTOMER_MESSAGES (FromID int, ToID int) ...
    (microsoft.public.sqlserver.server)
  • Re: Table design teaser
    ... Drop the distinction between staff and customer. ... > CUSTOMER (ID int pk, ... STAFF_CUSTOMER_MESSAGES (FromID int, ToID int) ...
    (microsoft.public.sqlserver.server)