0

How can I give the long text as a table field name in mysql?

Here is what I tried:

CREATE TABLE IF NOT EXISTS surveyForm_8(
    surveyForm_8_id INT NOT NULL AUTO_INCREMENT, 
    PRIMARY KEY(surveyForm_8_id), 
    survey_form_id VARCHAR(255), 
    submitted_by VARCHAR(15), 
    submitted_on TIMESTAMP, 
    'How_to_change_the_way_of_road?' VARCHAR(255)
)

But I got this error:

#1059 error
KatieK
  • 13,586
  • 17
  • 76
  • 90
Siva G
  • 1,170
  • 3
  • 17
  • 35
  • possible duplicate of [MySQL - when to use single quotes, double quotes, and backticks?](http://stackoverflow.com/questions/11321491/mysql-when-to-use-single-quotes-double-quotes-and-backticks) – Michael Berkowski Jan 09 '13 at 13:51
  • You need to quote it with backticks `\`How_to_change_the_way_of_road?\`` though I would recommend against including the `?` in the table name. – Michael Berkowski Jan 09 '13 at 13:51
  • @MichaelBerkowski it is not coming... – Siva G Jan 09 '13 at 13:53
  • @MichaelBerkowski I definitely agree what you've said but is not error `#1059` thrown because of length of the column name? – Leri Jan 09 '13 at 13:54
  • The backticks worked for me when I tried it. – Tom Jan 09 '13 at 13:54
  • Check this link http://dev.mysql.com/doc/refman/5.5/en/identifiers.html. You can specify column name maximum 64 characters long – Saharsh Shah Jan 09 '13 at 13:54
  • @SaharshShah i need more than 64 convectors is possible? or suggest me any other way?... – Siva G Jan 09 '13 at 13:57

2 Answers2

1

Try this one, you should use the ` symbol for column names

  CREATE TABLE IF NOT EXISTS surveyForm_8(surveyForm_8_id INT NOT NULL AUTO_INCREMENT,
     PRIMARY KEY(surveyForm_8_id), survey_form_id varchar(255) ,submitted_by varchar(15),
     submitted_on timestamp, `How_to_change_the_way_of_road?` varchar(255));
Nick
  • 602
  • 9
  • 22
0

Please see http://dev.mysql.com/doc/refman/5.5/en/identifiers.html for valid table and field names.

Basically, double quotes only work in ANSI_QUOTES mode. The default is to use `backticks` to quote. Also, the maximum length of table / field names is 64 characters.

riha
  • 2,270
  • 1
  • 23
  • 40