in sql i have a table of items. An item can have multiples prices. But when i come to using the data, most of the time i only need the currentPrice that i can find with the date.
My question : Would it be wrong to have 2 relation on price where and Item would have a relation with the currentPrice and all the price. Do there is a solution for this kind of problem to prevent complication in my mvc. Im currently using a viewModel with and the current price but if i could handle this in the database it seem better to me. (tell me if its not).
Note: I don't think this exact methode would work since I would need to create my price table before my item table and the same for the item table. But this show my problem.
Thanks alot for your help.
CREATE TABLE Item.Items
(
ItemId INT NOT NULL
CONSTRAINT PK_Items_ItemId
PRIMARY KEY
IDENTITY,
--------------------------------------------------
--CurrentPriceId INT NOT NULL
CONSTRAINT FK_Prices_Items
FOREIGN KEY REFERENCES Item.Items (ItemId),
--------------------------------------------------
Name VARCHAR(100) NOT NULL,
Points INT NOT NULL DEFAULT 0,
Description VARCHAR(5000) NULL
)
CREATE TABLE Item.Prices
(
PriceId INT NOT NULL
CONSTRAINT PK_ItemPrices_ItemPriceId
PRIMARY KEY
IDENTITY,
ItemId INT NOT NULL
CONSTRAINT FK_ItemPrices_Item
FOREIGN KEY REFERENCES Item.Items (ItemId),
EffectiveDate DATETIME NOT NULL,
Value MONEY NOT NULL
)