MikeMikeMike Posted May 18, 2011 Share Posted May 18, 2011 On page 169, it lists the SQL for the various tables. In the Carts table, for example, there is a primary key, but there is also a "Key" for product type and a "Key" for user id Some of the code looks like this PRIMARY KEY (`id`), KEY `product_type` (`product_type`, `product_id`), KEY `user_session_id`(`user_session_id`) Questions: 1) what is the purpose of the KEY? Please explain by comparing to PRIMARY KEY and also UNIQUE KEY, which is found in other tables. 2) Why is the input formatted that way for KEY. i.e. it has a name in quotes `product_type` and then it has more data after in parentheses? Link to comment Share on other sites More sharing options...
Larry Posted May 18, 2011 Share Posted May 18, 2011 KEY is jut a synonym for INDEX. So there are general indexes being created there. UNIQUE KEY is just a more specific type of index. PRIMARY KEY is jut a more specific type of UNIQUE index. The syntax for creating any index in MySQL is: INDEX_TYPE name (columns) With the name being optional. The backticks are just the optimal way to reference column names and other database elements (to avoid potential conflicts with MySQL reserved words), although I don't always use them myself. Link to comment Share on other sites More sharing options...
HartleySan Posted May 18, 2011 Share Posted May 18, 2011 Also, check this out: http://dev.mysql.com/doc/refman/5.0/en/mysql-indexes.html 1 Link to comment Share on other sites More sharing options...
Recommended Posts