SQL Syntax Error in Trying to Create Table

Discussion in 'Databases' started by wchung, Jan 31, 2012.

  1. #1
    I am unable to create the following sample table:

    CREATE TABLE cds (
    -> cdID INT(3) AUTO_INCREMENT PRIMARY KEY,
    -> artist VARCHAR(20),
    -> title VARCHAR(30),
    -> year INT(4),
    -> label VARCHAR(20),
    -> bought DATE );

    I keep getting the error message:

    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 '-> cdname INT(3) AUTO_INCREMENT PRIMARY KEY,
    -> artist VARCHAR(20),
    -> title V' at line 2 – 51 ms

    What is wrong with the query. It's something I saw in an online instruction manual.
     
    wchung, Jan 31, 2012 IP
  2. iama_gamer

    iama_gamer Active Member

    Messages:
    404
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    60
    #2
    you need to get rid of the arrows ->
     
    iama_gamer, Jan 31, 2012 IP
  3. wchung

    wchung Peon

    Messages:
    2
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    That did the trick! You're wonderful.
     
    wchung, Jan 31, 2012 IP
  4. mmerlinn

    mmerlinn Prominent Member

    Messages:
    3,197
    Likes Received:
    819
    Best Answers:
    7
    Trophy Points:
    320
    #4
    Hmm, if all else fails, READ THE MANUAL. If you had read the manual, you would have had it fixed BEFORE you posted the question.
     
    mmerlinn, Feb 2, 2012 IP
  5. ezprint2008

    ezprint2008 Well-Known Member

    Messages:
    611
    Likes Received:
    15
    Best Answers:
    2
    Trophy Points:
    140
    Digital Goods:
    1
    #5
    LOL that was your old output file huh? :D
     
    ezprint2008, Feb 5, 2012 IP
  6. ivickon

    ivickon Peon

    Messages:
    32
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    The following works in a new MySQL session:

    CREATE DATABASE rand27818;
    USE rand27818;
    CREATE TABLE sessions (id INT NOT NULL AUTO_INCREMENT, session VARCHAR(128), PRIMARY KEY(id));
    DROP DATABASE rand27818;
    However, this--

    SET @sesslen = 128;
    CREATE DATABASE rand27818;
    USE rand27818;
    CREATE TABLE sessions (id INT NOT NULL AUTO_INCREMENT, session VARCHAR(@sesslen), PRIMARY KEY(id));
    DROP DATABASE rand27818;
     
    ivickon, Feb 25, 2012 IP