私はテーブルを持っています
items
products
brands
その内容:
products:
- samsung galaxy s2
- iphone 5
brands
- samsung
- apple
アイテムと製品の違いは次のとおりです。
製品はiPhoneとしましょう。
アイテムは、特定のユーザーの特定の iPhone であり、色や購入価格などの独自のプロパティがあります。
製品 iPhone には Apple のブランド/メーカーがあります。
新しいアイテムを挿入するとき、データベースがアイテムが属する製品からブランドを取得するようにしたいので、外部キーは次のように設定されます。
'db_name`.'products'.`productBrand`
Samsung と Apple という 2 つのブランドの ATM があります。
phpMyAdmin のインターフェイスを介して新しいアイテムを挿入しようとして、itemBrand 列に到達すると、製品 1 または 2 (Samsung Galaxy または iPhone5) を選択したかどうかに関係なく、ドロップダウン フィールドには 1 (Samsung) の 1 つのオプションのみが許可されます。 itemGenericProduct 列にあります。
私は何を間違っていますか?
より詳細な情報は次のとおりです。
CREATE TABLE IF NOT EXISTS `brands` (
`brandId` int(11) NOT NULL AUTO_INCREMENT,
`brandName` varchar(30) NOT NULL,
`brandLogo` varchar(100) NOT NULL,
`brandDescription` text NOT NULL,
PRIMARY KEY (`brandId`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=3 ;
--
-- Dumping data for table `brands`
--
INSERT INTO `brands` (`brandId`, `brandName`, `brandLogo`, `brandDescription`) VALUES
(1, 'Samsung', '', 'Manufacturer of ...'),
(2, 'Apple', '', 'American high-tech company ...');
--
-- Table structure for table `items`
--
CREATE TABLE IF NOT EXISTS `items` (
`itemId` int(11) NOT NULL AUTO_INCREMENT,
`generalProductId` int(11) NOT NULL,
`itemPurchasedPrice` double NOT NULL,
`itemDateAdded` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
`itemDescription` text,
`itemBrand` int(11) NOT NULL,
`itemBoughtFromPlace` int(11) NOT NULL,
`itemBoughtFromUser` int(11) NOT NULL,
`itemConditionNew` tinyint(1) NOT NULL DEFAULT '1',
`itemBeingSold` tinyint(1) NOT NULL DEFAULT '1',
`itemSellPrice` double DEFAULT NULL,
PRIMARY KEY (`itemId`),
KEY `generalProductId` (`generalProductId`),
KEY `itemBrand` (`itemBrand`),
KEY `itemBoughtFromPlace` (`itemBoughtFromPlace`),
KEY `itemBoughtFromUser` (`itemBoughtFromUser`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;
--
-- Table structure for table `products`
--
CREATE TABLE IF NOT EXISTS `products` (
`productId` int(11) NOT NULL AUTO_INCREMENT,
`productName` varchar(200) NOT NULL,
`productTimeAdded` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
`productDescription` text,
`productBrand` int(11) NOT NULL,
`productFirstAddedFrom` int(11) NOT NULL,
`productAvatar` varchar(100) DEFAULT NULL,
PRIMARY KEY (`productId`),
KEY `productBrand` (`productBrand`,`productFirstAddedFrom`),
KEY `productFirstAddedFrom` (`productFirstAddedFrom`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=5 ;
--
-- Dumping data for table `products`
--
INSERT INTO `products` (`productId`, `productName`, `productTimeAdded`, `productDescription`, `productBrand`, `productFirstAddedFrom`, `productAvatar`) VALUES
(3, 'Samsung Galaxy SII', '2013-10-26 07:46:08', 'The Samsung Galaxy S II is a .....', 1, 1, NULL),
(4, 'iPhone 5', '2013-10-26 07:46:08', 'The iPhone 5 is a ....', 1, 2, NULL);
編集: PRODUCTS テーブルの次の行は奇妙に思えます
KEY `productBrand` (`productBrand`,`productFirstAddedFrom`),
KEY `productFirstAddedFrom` (`productFirstAddedFrom`)
視覚的なレイアウトでは、次のように見えるためです。