0

I'm trying to use this code:

CREATE TABLE cjlm_messages (uuid VARCHAR(100) PRIMARY KEY, join VARCHAR(500), leave VARCHAR(500));

to create a table with columns (uuid--already defined by client), join (a string no longer than 500 characters), and leave (same). It gives the following error:

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 'join >VARCHAR(500), leave VARCHAR(500), PRIMARY KEY (uuid))' at line 1

I'm new to SQL, so any help is appreciated. I briefly looked through the docs and online manuals, and it seems like this should be the correct way.

AniSkywalker
  • 449
  • 5
  • 20
  • 3
    `join` is a reserved word. Change the column name to something else. – sstan Dec 24 '15 at 15:38
  • 1
    Possible duplicate of [How do I escape reserved words used as column names? MySQL/Create Table](http://stackoverflow.com/questions/2889871/how-do-i-escape-reserved-words-used-as-column-names-mysql-create-table) – Norbert Dec 24 '15 at 15:42
  • @NorbertvanNobelen While that works, escaping reserved words is a super bad idea.. :) Unless you want your code to be incomprehensible! – David Hoelzer Dec 24 '15 at 15:44
  • Notice how the word *join* appears in blue above. You might keep an eye out for that if you have syntax highlighting in your editor. As for *leave*, obviously you can't rely on it for vendor-specific restrictions. – shawnt00 Dec 24 '15 at 15:45
  • 1
    I would aim at always avoiding reserved words, i would not even include them as part of a table or column name. It just makes for code thats easier to read rather than having to decipher it. – CodingInTheUK Dec 24 '15 at 16:05
  • @DavidHoelzer: I agree, however this possible duplicate I added is more of the style: Google and you will find the answer. – Norbert Dec 25 '15 at 17:21

1 Answers1

3

Join is a reserved word. You cannot use it as a column name.

David Hoelzer
  • 15,862
  • 4
  • 48
  • 67