Fork me on GitHub Fork me on Gitee

MySQL语句创建表、插入数据遇到的问题-20/4/18

问题:

1.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 '1)' at line 1

2.MySQL数据库插入数据时,出现Unknown column 'XXX' in 'field list' 问题('XXX'表示任意字符)。

分析

  • 单引号、反单引号分不清
    • 字符用(')单引号,列名用(`)反单引号--->键盘数字键最左边~符号那个,shift可切换为反单引号。

注意:反单引号可用来解决列名包括SQL关键字的问题。
发现上述问题,解决示例:

CREATE TABLE users(
	id INT PRIMARY KEY,
	`name` VARCHAR(40),
	`password` VARCHAR(40),
	email VARCHAR(60),
	birthday DATE
);
INSERT INTO users(id,`name`,`password`,email,birthday)
VALUES(1,'张三','123456','zs@qq.com','2000-01-01');
INSERT INTO users(id,`name`,`password`,email,birthday)
VALUES(2,'李四','123','ls@qq.com','2001-01-01');
INSERT INTO users(id,`name`,`password`,email,birthday)
VALUES(3,'王五','1234','ww@qq.com','2002-01-01');

SELECT * FROM users;
posted on 2020-04-18 10:25  mellisa&myt  阅读(168)  评论(0编辑  收藏  举报