Hi there, I've been following a tutorial and in it a Categories table has to be created, the tutorial gives the following sql CREATE TABLE IF NOT EXISTS 'categories' ( 'id' int (10) unsigned NOT NULL auto_increment, 'parent_id' int(11) NOT NULL default '0', 'name' varchar(50) character NOT NULL, 'description' varchar(200) character NOT NULL, PRIMARY KEY ('id'), KEY 'cat_parent_id' ('parent_id'), KEY 'cat_name' ('name') ); The last two lines (eg KEY 'cat_name' ('name')) I'm not too sure about what that means. I've googled and only found out that it might have something to do with indexes. From what I've read I understand indexes (sort of) but I can't find anywhere which uses that KEY instruction when creating a table. Any other article I find about indexes uses something like: CREATE INDEX IDX_CUSTOMER_LAST_NAME on CUSTOMER (Last_Name) Can anyone explain what exactly KEY does, and what the 'cat_name' ('name') beside it means, is cat_name and alias? Obviuosly 'name' is the column in the table that the instruction is dealing with. confused...
Read up about keys on wikipedia, start with the basics of Primary Key, Secondary Keys and Foreign Keys http://en.wikipedia.org/wiki/Primary_key
KEY and INDEX are interchangeable keywords, they mean the same thing. KEY 'cat_parent_id' ('parent_id') = Create an index on the 'parent_id' column. Name this index 'cat_parent_id'. KEY 'cat_name' ('name') = Create an index on the 'name' column named. Name this index 'cat_name'. Here's the syntax for the create statement, look for {INDEX|KEY} in the text: http://dev.mysql.com/doc/refman/5.1/en/create-table.html This explains what an index is for: http://dev.mysql.com/doc/refman/5.0/en/mysql-indexes.html