更新
我试过运行这个
CREATE TABLE IF NOT EXISTS 'stickynotes'.'stickynotes' ('id' INT NOT NULL AUTO_INCREMENT ,
'note' VARCHAR(255) NULL ,
'created' TIMESTAMP NOT NULL ,
PRIMARY KEY ('id') ,
UNIQUE INDEX 'id_UNIQUE' ('id' ASC) )
ENGINE = MyISAM;
我收到错误#1064 - 您的SQL语法出错了;查看与您的MySQL服务器版本相对应的手册,以获得正确的语法,以便在附近的' stickynotes'。' stickynotes' (' id' INT NOT NULL AUTO_INCREMENT,' note' VARCHAR(' at line 1
当我尝试运行下面的sql查询时,我收到错误,#1064 - 您的SQL语法出错了;查看与您的MySQL服务器版本相对应的手册,以获得正确的语法,以便在附近使用' stickynotes'。' stickynotes''在第1行
查询有什么问题?
DROP TABLE IF EXISTS `stickynotes`.`stickynotes` ;
CREATE TABLE IF NOT EXISTS `stickynotes`.`stickynotes` (
`id` INT NOT NULL AUTO_INCREMENT ,
`note` VARCHAR(255) NULL ,
`created` TIMESTAMP NOT NULL ,
PRIMARY KEY (`id`) ,
UNIQUE INDEX `id_UNIQUE` (`id` ASC) )
ENGINE = MyISAM;
-- -----------------------------------------------------
-- Data for table `stickynotes`.`stickynotes`
-- -----------------------------------------------------
START TRANSACTION;
USE `stickynotes`;
INSERT INTO `stickynotes`.`stickynotes` (`id`, `note`, `created`) VALUES (NULL, 'This is a sticky note you can type and edit.', NULL);
INSERT INTO `stickynotes`.`stickynotes` (`id`, `note`, `created`) VALUES (NULL, 'Let's see if it will work with my iPhone', NULL);
COMMIT;
答案 0 :(得分:1)
问题在于:
INSERT INTO
stickynotes
。stickynotes
(id
,note
,created
) VALUES(NULL,'让我们看看它是否适用于我的iPhone',NULL);
尝试:
INSERT INTO
stickynotes
。stickynotes
(id
,note
,created
) VALUES(NULL,'让我们看看它是否适用于我的iPhone',NULL);
错误在于:让我们看看它是否适用于我的iPhone
答案 1 :(得分:0)
首先,您已经定义了USE
stickynotes`,因此在插入内部使用模式名称是没有意义的
其次,您尚未转发Let's
应该是'Let\'s
INSERT INTO `stickynotes`.`stickynotes` (`id`, `note`, `created`)
VALUES (NULL, 'Let\'s see if it will work with my iPhone', NULL);
完整代码块:
DROP TABLE IF EXISTS `stickynotes`.`stickynotes` ;
CREATE TABLE IF NOT EXISTS `stickynotes`.`stickynotes` (
`id` INT NOT NULL AUTO_INCREMENT ,
`note` VARCHAR(255) NULL ,
`created` TIMESTAMP NOT NULL ,
PRIMARY KEY (`id`) ,
UNIQUE INDEX `id_UNIQUE` (`id` ASC) )
ENGINE = MyISAM;
-- -----------------------------------------------------
-- Data for table `stickynotes`.`stickynotes`
-- -----------------------------------------------------
START TRANSACTION;
USE `stickynotes`;
INSERT INTO stickynotes (`id`, `note`, `created`) VALUES (NULL, 'This is a sticky note you can type and edit.', NULL);
INSERT INTO stickynotes (`id`, `note`, `created`) VALUES (NULL, 'Let\'s see if it will work with my iPhone', NULL);
COMMIT;
答案 2 :(得分:0)
您的第二次插入查询失败,即
INSERT INTO `stickynotes`.`stickynotes`
(`id`, `note`, `created`)
VALUES (NULL, 'Let's see if it will work with my iPhone', NULL);
您的Let's see if it will work with my iPhone
值为Let's
,'
引用'
,列值包含在id
中,因此将其视为非法,即将其重新设为1} p>
在表格中插入note
,created
,s see if it will work with my iPhone'
列,其值为
NULL
'设'
看看它是否适用于我的iPhone'
NULL
所以这里\
抛出了语法错误
你需要使用INSERT INTO `stickynotes`.`stickynotes`
(`id`, `note`, `created`)
VALUES (NULL, 'Let\'s see if it will work with my iPhone', NULL);
来逃避它,以便mysql知道引用是值的一部分而不是整个列值
{{1}}
如果您使用应用程序级别来执行带有预准备语句的插入操作,则需要注意这一点。