cfarm Posted June 17, 2011 Share Posted June 17, 2011 Why do you have two keys in the categories declaration on page 51 for your categories table? And also what is the difference between a primary and unique key? CREATE TABLE categories( id SMALLINT NOT NULL AUTO INCREMENT, category VARCHAR(30) NOT NULL, PRIMARY KEY ('id'), UNIQUE KEY 'category' ('category') ) Link to comment Share on other sites More sharing options...
Jonathon Posted June 17, 2011 Share Posted June 17, 2011 A unique key is similar to a primary key. But you can have more than 1 unique key if you wanted to. You can only have 1 primary key often it is just a row_id that increments as items are added to the database. The unique index speeds up searching on that particular column to look for duplicates. You'll see examples of a unique keys being used in other works of Larry's such as 'username' or 'email' columns. Does that explain it for you? 2 Link to comment Share on other sites More sharing options...
cfarm Posted June 17, 2011 Author Share Posted June 17, 2011 Yes thanks for the help. I've been looking for some documentation on UNIQUE KEY but haven't found any. Do you know where I would be able to look? Link to comment Share on other sites More sharing options...
Jonathon Posted June 17, 2011 Share Posted June 17, 2011 Have you tried the MYSQL website? If this is your first programming book, it might serve you well to read Larry's PHP6 and MYSQL 5, which he is re-writing now and meant to be out the end of summer I think? 1 Link to comment Share on other sites More sharing options...
Larry Posted June 17, 2011 Share Posted June 17, 2011 Yes, to be clear, this book assumes complete comfort with basic to intermediary PHP and MySQL. It teaches some advanced application of these languages, but doesn't teach these languages in themselves. Link to comment Share on other sites More sharing options...
Recommended Posts