MySQL在创建和插入数据时收到语法错误

时间:2019-11-25 17:07:38

标签: mysql sql mysql-5.6

我创建一个表格

create table if not exists gbpExchangeRates (
    date date
    , to_currency char(3)
    , rate float
    , index idx (date, to_currency)
);

然后添加然后尝试插入数据

INSERT INTO gbpExchangeRates ('date', 'to_currency', 'rate') VALUES ('2018-01-22', 'CAD', 1.7253437447) ;

但是我收到以下错误

SQL Error [1064] [42000]: 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 ''date', 'to_currency', 'rate') VALUES ('2018-01-22', 'CAD', 1.7253437447)' at line 1

我尝试了以下操作,但仍收到错误消息:

  • ALTER TABLE gbpExchangeRates MODIFY to_currency char(10);
  • ALTER TABLE gbpExchangeRates MODIFY to_currency varchar(10);
  • ALTER TABLE gbpExchangeRates MODIFY rate double;
  • ALTER TABLE gbpExchangeRates MODIFY to_currency varchar(10);
  • INSERT INTO gbpExchangeRates ('date', 'to_currency', 'rate') VALUES ('2018-01-22', 'CAD', 1.72) ;
  • 的变体

我的表和/或插入语句怎么了?

3 个答案:

答案 0 :(得分:2)

INSERT INTO gbpExchangeRates (date, to_currency, rate) VALUES ('2018-01-22', 'CAD', 1.7253437447) ;

您不需要将字段引号插入

答案 1 :(得分:0)

字段名称不带引号,或者您可以使用反引号

答案 2 :(得分:0)

删除单引号

INSERT INTO gbpExchangeRates (date, to_currency, rate) VALUES
('2018-01-22', 'CAD', 1.7253437447) ;