Thread: newbie
View Single Post
  #21 (permalink)  
Old 08-30-10, 12:22
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,524
Quote:
Originally Posted by twinkiejr View Post
What field in the inventory table would go in the variety table as the key.
mine eyes, zey are bleedink!!! ze goggles, zey do nossink!!!

please, learn to format your SQL

thank you

Code:
CREATE TABLE `inventory` 
( `inventory id` int(15) NOT NULL AUTO_INCREMENT
, `type #` int(6) NOT NULL
, `category #` int(6) NOT NULL
, `country #` int(9) NOT NULL
, `year variety #` int(9) NOT NULL
, `grade #` int(6) NOT NULL
, `grade modifier #` int(6) NOT NULL
, `description` varchar(250) NOT NULL
, `long description` varchar(250) NOT NULL
, `catalog #` varchar(9) NOT NULL
, `special 1` varchar(12) NOT NULL
, `special 2` varchar(12) NOT NULL
, `special 3` varchar(12) NOT NULL
, `certification #` int(3) NOT NULL
, `location #` int(3) NOT NULL
, `remarks` text NOT NULL
, `status code` varchar(4) NOT NULL
, `retail price` decimal(10,2) NOT NULL
, `user #` int(4) NOT NULL
, `entry date` date NOT NULL
, `quantity` int(4) NOT NULL
, `cost code` varchar(12) NOT NULL
, `purchase date` date NOT NULL
, `purchase price` decimal(10,2) NOT NULL
, `purchase location` varchar(12) NOT NULL
, `sold date` date NOT NULL
, `sold price` decimal(10,2) NOT NULL
, `order #` int(15) NOT NULL
, `barcode #` int(12) NOT NULL
, PRIMARY KEY (`inventory id`)
, KEY `country #` (`country #`)
, KEY `grade #` (`grade #`)
, KEY `grade modifier #` (`grade modifier #`)
, KEY `certification #` (`certification #`)
, KEY `location #` (`location #`)
, KEY `status code` (`status code`)
, KEY `user #` (`user #`)
, KEY `order #` (`order #`)
, KEY `sold price` (`sold price`)
, KEY `sold date` (`sold date`)
, KEY `type #_2` (`type #`
,`category #`
,`year variety #`)
, KEY `category #` (`category #`)
, KEY `year variety #` (`year variety #`)
, CONSTRAINT `inventory_ibfk_17` FOREIGN KEY (`year variety #`) REFERENCES `year_variety` (`year/variety #`) ON UPDATE CASCADE
, CONSTRAINT `inventory_ibfk_14` FOREIGN KEY (`grade #`) REFERENCES `grade` (`grade #`)
, CONSTRAINT `inventory_ibfk_15` FOREIGN KEY (`category #`) REFERENCES `category` (`category #`) ON UPDATE CASCADE
, CONSTRAINT `inventory_ibfk_16` FOREIGN KEY (`type #`) REFERENCES `type` (`type #`) ON UPDATE CASCADE
, CONSTRAINT `inventory_ibfk_2` FOREIGN KEY (`certification #`) REFERENCES `certification` (`certification #`) ON UPDATE CASCADE
, CONSTRAINT `inventory_ibfk_3` FOREIGN KEY (`grade modifier #`) REFERENCES `grade_modifier` (`grade modifier #`) ON UPDATE CASCADE
, CONSTRAINT `inventory_ibfk_4` FOREIGN KEY (`user #`) REFERENCES `users` (`user #`) ON UPDATE CASCADE
, CONSTRAINT `inventory_ibfk_5` FOREIGN KEY (`country #`) REFERENCES `country` (`country #`) ON UPDATE CASCADE
, CONSTRAINT `inventory_ibfk_6` FOREIGN KEY (`location #`) REFERENCES `location` (`location #`) ON UPDATE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8
what are the primary and unique keys in the year/variety table? that will tell you which keys you can reference in a FK from the inventory table
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote