If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > the use of KEY in a CREATE TABLE instruction

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 03-10-11, 10:26
barricades barricades is offline
Registered User
 
Join Date: Mar 2011
Posts: 1
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.

confused...
Reply With Quote
  #2 (permalink)  
Old 03-10-11, 10:37
r937 r937 is online now
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,535
in the CREATE (or ALTER) TABLE syntax, KEY is a synonym for INDEX

it's all explained quite nicely in the manual

__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On