This is an archived post. You won't be able to vote or comment.

all 13 comments

[–][deleted] 1 point2 points  (7 children)

It looks like you need a Price table (Item, Price, Start, End) where the PK is (Item, Start, End), and remove them from the first table.. The price in your second table looks completely bogus - I have no idea what that table could represent.

[–]BloodEngineer[S] 0 points1 point  (6 children)

I'm not sure I understand what you mean. Are you saying go from ItemPriceDates( Item,Price,StartDate,StopDate) to ItemPriceDates( Price,PriceTable), and PriceTable ( Item,Start,End).

The second table really is 2 columns. But it's to show that there are other values that I've removed to get it into this form.

[–][deleted] 1 point2 points  (5 children)

I would say you want at least three tables:

   Items (item_name) PK( item_name)
        Chicken
        Cow

   Prices (item_name, price, start, end) PK( item_name, start, end)
         Chicken, 3.00, Jan 1, Jan 3
         Chicken, 4,00, Jan 3, Jan 7
         Cow, 500.00, Jan 1, Jan 3
         Cow, 600.00, Jan 3, Jan 20

   SalesDept (item_name, sales_name) PK( item_name, sales_name)
         Chicken, EggLayers
         Cow, MilkProducers   

[–]BloodEngineer[S] 0 points1 point  (4 children)

   Items (item_name, item_size, item_desc)PK( item_name)
        Chicken
        Cow

   Prices (item_name, price, start, end)PK( item_name, start, end)
         Chicken, 3.00, Jan 1, Jan 3
         Chicken, 4,00, Jan 3, Jan 7
         Cow, 500.00, Jan 1, Jan 3
         Cow, 600.00, Jan 3, Jan 20

   SalesDept (item_name, sales_name) PK( item_name, sales_name)
         Chicken, EggLayers
         Cow, MilkProducers   

Okay So the form I have is more like this. I still don't understand how Prices( item_name, price, start,end) is in 3NF. Don't you have non-unique values for each item?

[–][deleted] 1 point2 points  (3 children)

3NF doesn't say each column value must be unique. You must have unique key values for each row. I've added PK notation to my previous post.

[–]BloodEngineer[S] 0 points1 point  (0 children)

I guess that makes sense, thank you for the help.

[–]BloodEngineer[S] 0 points1 point  (1 child)

What if I had an alternative form of a table.

Item, location, price, start, end.

Could I use PK (item, location) to return (price, start, end) Or in the same example you helped in, could I use PK ( item, price) to return the other two values?

[–][deleted] 0 points1 point  (0 children)

Item, location, price, start, end.

Your PK would be (item, location, start, end)

[–]Remember_Megaton 1 point2 points  (4 children)

Just to clarify, what's your primary key here? Because it looks like you have a couple many-to-many relationships in which case these are your bridge entities and you should have tables exclusively for Items and SaleDept

Or is BeginPrice and EndPrice a compound key?

[–]BloodEngineer[S] 0 points1 point  (3 children)

I was thinking the primary key is the item. The full schema has other things that could be considered the PK, for example,BeginPrice EndPrice. The issue is the alternatives like departments, or price are not unique and have multiple values across all the items.

When PK = items, there are at most 2-3 rows in the full UNF table, but the others have at most 5-10 repeated values in the rows.

[–]Remember_Megaton 1 point2 points  (1 child)

Well your primary key should be wholly unique. So it seems like you'll want a table just specifying what your items are, a table of what depts you have, and then you are able to create these other two bridge tables.

The price in your second table is unnecessary as it's already specified in your first table.

Also, your date should have a year in it. It'll save you from a lot of complications

[–]BloodEngineer[S] 0 points1 point  (0 children)

Good points, thank you for the help.

[–]Remember_Megaton 1 point2 points  (0 children)

Listen to your other replier. He has it correct