Results 1 to 2 of 2
  1. #1
    Join Date
    Mar 2011

    Unanswered: the use of KEY in a CREATE TABLE instruction

    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.


  2. #2
    Join Date
    Apr 2002
    Toronto, Canada
    in the CREATE (or ALTER) TABLE syntax, KEY is a synonym for INDEX

    it's all explained quite nicely in the manual | @rudydotca
    Buy my SitePoint book: Simply SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts