MySQL 创建和插入数据时收到语法错误
MySQL receiving syntax error when creating and inserting data
我创建一个table
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) ;
- 和
的变体
我的 table and/or 插入语句有什么问题?
INSERT INTO gbpExchangeRates (date, to_currency, rate) VALUES ('2018-01-22', 'CAD', 1.7253437447) ;
要插入的字段不需要引号
字段名称不带引号,或者您可以使用反引号
去掉单引号
INSERT INTO gbpExchangeRates (date, to_currency, rate) VALUES
('2018-01-22', 'CAD', 1.7253437447) ;
我创建一个table
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) ;
- 和 的变体
我的 table and/or 插入语句有什么问题?
INSERT INTO gbpExchangeRates (date, to_currency, rate) VALUES ('2018-01-22', 'CAD', 1.7253437447) ;
要插入的字段不需要引号
字段名称不带引号,或者您可以使用反引号
去掉单引号
INSERT INTO gbpExchangeRates (date, to_currency, rate) VALUES
('2018-01-22', 'CAD', 1.7253437447) ;