What is KEY?

The following code - from my book - is not working…

CREATE TABLE `orders`(
`id` INT UNSIGNED NOT NULL AUTO_INCREMENT,
`user_id` INT UNSIGNED NOT NULL,
`transaction_id` VARCHAR(19) NOT NULL,
`payment_status` VARCHAR(15) NOT NULL,
`payment_amount` DECIMAL(6,2) UNSIGNED NOT NULL,
`payment_date_time` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
PRIMARY_KEY(`id`),
KEY `user_id` (`user_id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;

phpMyAdmin says there is an error around “KEY”…

What is KEY??

And any ideas why this query won’t work?

Thanks,

TomTees

KEY is simply a synonym for INDEX (you do understand indexes, right?), whereas what kalon linked to was some generic stuff about primary and foreign keys, which doesn’t apply to the KEY you’re using

the error i am referring to is the one you posted, it is caused by something on the line immediately above the KEY line

more specifically (thanks, kalon) it is near COLOR=“Red”[/COLOR]

find that and you’re almost there :slight_smile:

the key in your error message is referring to a problem with

[KEY](http://databases.about.com/od/specificproducts/a/keys.htm) `user_id` [COLOR=#66cc66]([/COLOR]`user_id`[COLOR=#66cc66])[/COLOR]

kalon, what you linked to is not what the mysql KEY is all, um, about (pardon the weak pun)

in mysql, KEY simply means INDEX

the real error is in the line above the line with KEY

:slight_smile:

yep, wrong link

the error I got when I ran the script in SQLyog is

Query : CREATE TABLE orders( id INT UNSIGNED NOT NULL AUTO_INCREMENT, user_id INT UNSIGNED NOT NULL, transaction_id VARCHAR(1…
Error Code : 1064
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '(id),
KEY user_id (user_id)
) ENGINE=MyISAM DEFAULT CHARSET=utf8’ at line 8
Execution Time : 00:00:00:000
Transfer Time : 00:00:00:000
Total Time : 00:00:00:000

Can you fill me in on what you are talking about?

What was KEY again?

And what error are you referring to?

TomTees

Yes, I do.

whereas what kalon linked to was some generic stuff about primary and foreign keys, which doesn’t apply to the KEY you’re using

I thought maybe KEY was short for FOREIGN KEY?! (I believe that is how the author is using that field.)

the error i am referring to is the one you posted, it is caused by something on the line immediately above the KEY line

more specifically it is near COLOR=“Red”[/COLOR]

find that and you’re almost there :slight_smile:

I forget what was wrong now?

I think I had “PRIMARY_KEY” instead of “PRIMARY KEY”.

TomTees

yep, that was it :slight_smile: