SitePoint Sponsor

User Tag List

Results 1 to 8 of 8

Thread: What is KEY?

  1. #1
    SitePoint Evangelist TomTees's Avatar
    Join Date
    Apr 2010
    Location
    Iowa
    Posts
    553
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    What is KEY?

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

    Code MySQL:
    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

  2. #2
    Non-Member Kalon's Avatar
    Join Date
    Aug 2010
    Location
    At my computer
    Posts
    2,012
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by TomTees View Post
    What is KEY??
    the key in your error message is referring to a problem with

    Code:
    KEY `user_id` (`user_id`)

  3. #3
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,247
    Mentioned
    59 Post(s)
    Tagged
    3 Thread(s)
    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

    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  4. #4
    Non-Member Kalon's Avatar
    Join Date
    Aug 2010
    Location
    At my computer
    Posts
    2,012
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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

  5. #5
    SitePoint Evangelist TomTees's Avatar
    Join Date
    Apr 2010
    Location
    Iowa
    Posts
    553
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by r937 View Post
    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

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

    What was KEY again?

    And what error are you referring to?


    TomTees

  6. #6
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,247
    Mentioned
    59 Post(s)
    Tagged
    3 Thread(s)
    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 (`id`)

    find that and you're almost there
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  7. #7
    SitePoint Evangelist TomTees's Avatar
    Join Date
    Apr 2010
    Location
    Iowa
    Posts
    553
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by r937 View Post
    KEY is simply a synonym for INDEX (you do understand indexes, right?),
    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 (`id`)

    find that and you're almost there
    I forget what was wrong now?

    I think I had "PRIMARY_KEY" instead of "PRIMARY KEY".


    TomTees

  8. #8
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,247
    Mentioned
    59 Post(s)
    Tagged
    3 Thread(s)
    Quote Originally Posted by TomTees View Post
    I think I had "PRIMARY_KEY" instead of "PRIMARY KEY".
    yep, that was it
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"


Bookmarks

Posting Permissions

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