2

When I try to run this script I am getting an error at "range" if I remove or change the name I can run the script however the application need this column to store data. Any idea how to insert this into MySQL?

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 '"range" CHAR(5) NOT NULL, range_max_value NUMERIC(18,3)' at line 22

CREATE TABLE My_table (
  chart_id                INTEGER NOT NULL,
  u_range                 CHAR(5),
  l_range                 CHAR(5),
  "range"               CHAR(5) NOT NULL,
  range_max_val         NUMERIC(18,3),
  range_min_val         NUMERIC(18,3),
  PRIMARY KEY (chart_id)
);
Bjoern
  • 15,244
  • 4
  • 40
  • 47
DoubleA9281
  • 39
  • 2
  • 8

3 Answers3

9

Range is a reserved keyword that needs to be escaped with backticks.

CREATE TABLE My_table (
  chart_id                INTEGER NOT NULL,
  u_range                 CHAR(5),
  l_range                 CHAR(5),
  `range`               CHAR(5) NOT NULL,
  range_max_val         NUMERIC(18,3),
  range_min_val         NUMERIC(18,3),
  PRIMARY KEY (chart_id)
);
ceejayoz
  • 171,474
  • 40
  • 284
  • 355
3

You should take a look at the reserved words list. Range is one of those words. You need to escape it with tick marks:

CREATE TABLE My_table (
  chart_id                INTEGER NOT NULL,
  u_range                 CHAR(5),
  l_range                 CHAR(5),
  `range`               CHAR(5) NOT NULL,
  range_max_val         NUMERIC(18,3),
  range_min_val         NUMERIC(18,3),
  PRIMARY KEY (chart_id)
);
Kermit
  • 33,206
  • 11
  • 83
  • 119
1

RANGE is a reserved word. http://dev.mysql.com/doc/refman/5.5/en/reserved-words.html

Alain Collins
  • 16,035
  • 2
  • 31
  • 54