Thread: Syntax error

    #1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2012
    Posts
    2
    Rep Power
    0

    Syntax error


    Honestly, I have no idea what I am doing wrong here..
    This is my query:

    MySQL Code:
     
    INSERT INTO 'categories' ('id', 'name') VALUES
    (1, 'Official'),
    (2, 'Game'),
    (3, 'Support'),
    (4, 'Community');


    This is the error I am getting:

    #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 ''categories' ('id', 'name') VALUES (1, 'Official'), (2, 'Game'), (3, 'Support'),' at line 1

    Here is some more information on the fields and such:

    Code:
    # Column    Type            Collation         Attributes  Null   Default   Extra
    1 id        int(100)                          UNSIGNED    No     None      AUTO_INCREMENT
    2 name      varchar(100)    latin1_swedish_ci             No     None
    Any help is greatly appreciated!
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Oct 2003
    Location
    Germany
    Posts
    2,788
    Rep Power
    349
    Firstly: you posted in the wrong forum. This is for Microsoft SQL Server which is a completely different thing than MySQL (which you are using).

    Secondly: you are using single quotes for identifiers, which is wrong. Single quotes are only used for character literals (aka strings). Not for anything else. Identifiers (table names, column names, ...) do not need any quotes.

    So you need to use:
    Code:
    INSERT INTO categories (id, name) VALUES
    (1, 'Official'),
    (2, 'Game'),
    (3, 'Support'),
    (4, 'Community');
    You might see some MySQL statements using those dreaded non-standard backticks for identifiers (`categories`). They are only needed if your identifier is a reserved word or contains special characters (such as spaces). If you find yourself in a position where you need a quoted identifier, it's better to use the standard quoting style using double quotes ("categories"). Or even better: use a different name.
    I will not read nor answer questions where the SQL code is messy and not formatted properly using [code] tags.
    http://forums.devshed.com/misc.php?do=bbcode#code

    Tips on how to ask better questions:
    http://tkyte.blogspot.de/2005/06/how-to-ask-questions.html
    http://wiki.postgresql.org/wiki/SlowQueryQuestions
    http://catb.org/esr/faqs/smart-questions.html
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2012
    Posts
    2
    Rep Power
    0
    Originally Posted by shammat
    Firstly: you posted in the wrong forum. This is for Microsoft SQL Server which is a completely different thing than MySQL (which you are using).

    Secondly: you are using single quotes for identifiers, which is wrong. Single quotes are only used for character literals (aka strings). Not for anything else. Identifiers (table names, column names, ...) do not need any quotes.

    So you need to use:
    Code:
    INSERT INTO categories (id, name) VALUES
    (1, 'Official'),
    (2, 'Game'),
    (3, 'Support'),
    (4, 'Community');
    You might see some MySQL statements using those dreaded non-standard backticks for identifiers (`categories`). They are only needed if your identifier is a reserved word or contains special characters (such as spaces). If you find yourself in a position where you need a quoted identifier, it's better to use the standard quoting style using double quotes ("categories"). Or even better: use a different name.
    Alright well thanks for the reply. Sorry about posting in the wrong forum.
  6. #4
  7. SQL Consultant
    Devshed Supreme Being (6500+ posts)

    Join Date
    Feb 2003
    Location
    Toronto Canada
    Posts
    27,280
    Rep Power
    4279
    Originally Posted by braskez
    MySQL Code:
     
    INSERT INTO 'categories' ('id', 'name') VALUES...
    yet another developer pwned by mysql's backticks

    you probably saw the backticks in somebody else's code and thought they were quotes

    they're actually backticks

    but you shouldn't be using them anyway, because they are only required if your table or column name contains a special character or is a reserved word, and you shouldn't allow those types of names

    thread moved to mysql forum
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

IMN logo majestic logo threadwatch logo seochat tools logo