Wednesday, March 28, 2012

Is this table design correct?

Hey Everyone,

Just had a quick question for you . I have these 3 tables that are related in some way - below are the structures. I know the structures are correct and they work fine. However, I am using Visio Enterprise Architect to design these tables and when I try to generate the code, I get an error saying that it does not like the table with 2 fields as the primary key. And I just wanted to get feedback to find out whether I am correct or Visio is.

Table: Orders
Columns:
OrderID int PK
Name varchar(100)
Phone varchar(20)

Table: Products
Columns:
ProductID int PK
Name varchar(100)

Table: OrderLineItems
Columns:
OrderID int PK
ProductID int PK
Price money

Thanks for any feedback.

Johnny DevA composite primary key is perfectly legitimate and is often useful if you have a link table, like in your case. The only thing that puzzles me is the Price column in the OrderLineItems table - shouldn't it be in the Products table?|||Hi Diplo,

Thanks for the response. This clears things up. Visio needs to be updated to support this.

The table structure that I posted in this message is not what I have. It was just a sample to demonstrate my case so I wont post my real tables (too complicated :). In fact, my tables are not even Order/Products related. But thanks anyway for catching that for others to see.sql

No comments:

Post a Comment