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,934
  • 4
  • 43
  • 48
DoubleA9281
  • 39
  • 2
  • 8

3 Answers3

10

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
  • 176,543
  • 40
  • 303
  • 368
4

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,827
  • 13
  • 85
  • 121
1

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

Alain Collins
  • 16,268
  • 2
  • 32
  • 55