Jump to content
Larry Ullman's Book Forums

First Site Database Design


Recommended Posts

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

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? ;)

  • Upvote 2
Link to comment
Share on other sites

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

 Share

×
×
  • Create New...