这里总结了常见的一些mysql错误,会不断更新。
要求大家将如下错误的每个单词都知道是什么意思,方便调错。
--1.语法错误:SQL syntax
[Err] 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 '(`sno`,`con`,`degree`) values (109,'9-888',99)' at line 1
--2.未知列:查看表中是否存在'con'该字段
[Err] 1054 - Unknown column 'con' in 'field list'
--3.超过列的值的范围:'degree'列的长度超了
[Err] 1264 - Out of range value for column 'degree' at row 1
--4.值数量与字段数量不匹配:
[Err] 1136 - Column count doesn't match value count at row 1
--5.存在重复的主键列
[Err] 1062 - Duplicate entry '3-105' for key 'PRIMARY'
--6.定义了多个主键
[Err] 1068 - Multiple primary key defined
--7.该表已存在
[Err] 1050 - Table 'grade' already exists
--8.找不到该表(该表不存在)
[Err] 1051 - Unknown table 'grade'
--9.数据库已存在,无法创建
[Err] 1007 - Can't create database 'user'; database exists
--10.数据库不存在,不能删除
[Err] 1008 - Can't drop database 'school'; database doesn't exist
--11.在where 语句中,'6-166'字段是未知的
[Err] 1054 - Unknown column '6-166' in 'where clause'
--12.日期格式不正确:取值范围:月:1-12 日:1-31
[Err] 1292 - Incorrect datetime value: '1100-02-80' for column 'tbirthday' at row 1
--13.子查询中返回字段数不唯一。
[Err] 1241 - Operand should contain 1 column(s)
-- 错误13示例:子查询中只需要查询sid的值,实际查询了sid 和 sname的值
select sname,sid from student where sid in(
select sid,sname from sc where score is not null and score !=""
);
-- 14.子查询返回值不唯一
[Err] 1242 - Subquery returns more than 1 row
--错误14示例:子查询中sid返回的结果值不唯一,父句中的where条件后的sid不能用=连接,应用in
select sname,sid from student where sid = (
select sid from sc where score is not null and score !=""
);
-- 注意,13和14的两种错误是不一样的。
--15.未选择数据库
[Err] 1046 - No database selected
--16.该列的列类型使用的约束或其他有问题。例如自增不能用于varchar类型的数据
[Err] 1063 - Incorrect column specifier for column 'id'