Is this good a design?
Date: Tue, 06 Mar 2001 17:54:18 +0000
Message-ID: <3AA5244A.4652CEC0_at_interbulletin.com>
I have a question about a relationship that I've used before and was wondering how correct it was:
CREATE TABLE CartContents
(CartID INTEGER NOT NULL,
ItemID INTEGER NOT NULL
REFERENCES Items(ItemID),
Quantity INTEGER NOT NULL,
PRIMARY KEY (CartID, ItemID));
Now the above would work fine if the customer could only place Items in his or her cart, but the cart needs to hold items OR packages.
In the past I've set up the CartContents table like this:
CREATE TABLE CartContents
(CartID INTEGER NOT NULL,
CartItemID INTEGER NOT NULL,
CartItemType CHAR(1) NOT NULL CHECK (CartItemType IN ('P', 'I')),
Quantity INTEGER NOT NULL,
PRIMARY KEY (CartID, CartItemID, CartItemType));
In this way the CartItemId can reference either an ItemID or a PackageID, tracked with CartItemType.
This has worked fine but I'm wondering a few things:
Thanks to all.
Submitted via WebNewsReader of http://www.interbulletin.com Received on Tue Mar 06 2001 - 18:54:18 CET