添加纪录问题;

global_boy 2002-11-13 09:27:51
我用create database创建了一个库member并建了2个表users和password;
当我用insert into users values("user1",password("1234"));添加纪录时出现如下提示:
ERROR 1136: Column count doesn't match value count at row 1
请问该如何解决?


:)
...全文
30 17 打赏 收藏 转发到动态 举报
写回复
用AI写文章
17 条回复
切换为时间正序
请发表友善的回复…
发表回复
shuixin13 2002-11-14
  • 打赏
  • 举报
回复
新学数据库吧,
用MySQL最好的,
它配置简单,
SQL也与标准差不多


建议看看这个,

SQL循序渐进
http://surpass.swpi.edu.cn/article/SQLst.zip
shuixin13 2002-11-14
  • 打赏
  • 举报
回复
咱们一个个来:
1、
mysql> insert into users values("admin","admin");
ERROR 1136: Column count doesn't match value count at row 1
解答:
这是因为在你的users表中只有一个字段,而你在插入时却写了两个字段,
所以报表的Column数与你所给定的值数目不匹配

2、
mysql> create
-> table users2
-> (
-> username varchar(20),
-> password varchar(20),
-> )
-> ;
ERROR 1064: You have an error in your SQL syntax. Check the manual that corresp
onds to your MySQL server version for the right syntax to use near ')' at line 6

解答:
因为你的SQL语句错了,你只定义了两个字段,“password varchar(20),”这句最后的“,”就不要了,
标准为
CREATE TABLE users (username VarChar(20), password VarChar(10));
global_boy 2002-11-14
  • 打赏
  • 举报
回复
mysql> create
-> table users2
-> (
-> username varchar(20),
-> password varchar(20),
-> )
-> ;
ERROR 1064: You have an error in your SQL syntax. Check the manual that corresp
onds to your MySQL server version for the right syntax to use near ')' at line 6
global_boy 2002-11-14
  • 打赏
  • 举报
回复
mysql> use member
Database changed
mysql> create table users2 (
-> username char(20),
-> password char(20),
-> );
ERROR 1064: You have an error in your SQL syntax. Check the manual that corresp
onds to your MySQL server version for the right syntax to use near ')' at line 4
global_boy 2002-11-14
  • 打赏
  • 举报
回复
thanks very much!
alsoran 2002-11-13
  • 打赏
  • 举报
回复
可以这么建表也create
table users2 (
username varchar(20),
password varchar(20),
);
alsoran 2002-11-13
  • 打赏
  • 举报
回复
你的users表只有一个username字段,上面的一定是不行啊,如果要插入的话只能是插入一个值
insert into users values("admin");

你该建一个表包含两个字段的,username 和password

create table users2 (
username char(20),
password char(20),
);

再插入该没问题了insert into users2 values("admin","admin");

global_boy 2002-11-13
  • 打赏
  • 举报
回复
mysql> describe password;
+----------+----------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+----------+----------+------+-----+---------+-------+
| password | char(20) | | | | |
+----------+----------+------+-----+---------+-------+
1 row in set (0.00 sec)
global_boy 2002-11-13
  • 打赏
  • 举报
回复
mysql> use member;
Database changed
mysql> describe users;
+----------+----------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+----------+----------+------+-----+---------+-------+
| username | char(20) | | | | |
+----------+----------+------+-----+---------+-------+
1 row in set (0.00 sec)
alsoran 2002-11-13
  • 打赏
  • 举报
回复
可能是你表建的有问题
describe users;
看一下你表的结构
global_boy 2002-11-13
  • 打赏
  • 举报
回复
mysql> insert into users values("admin","admin");
ERROR 1136: Column count doesn't match value count at row 1
shuixin13 2002-11-13
  • 打赏
  • 举报
回复
insert into users values("user1",password("1234"));
与你的users表结构不一样呀,
插入一定不行的
alsoran 2002-11-13
  • 打赏
  • 举报
回复
一个表可以完全解决你的问题的,建立两个字段 user和password
都设置成char

语句这样写应该就可以了
insert into users values("user1","yourpassword");

global_boy 2002-11-13
  • 打赏
  • 举报
回复
create table users (
username char(20) not null,
password char(20) not null,
);

alsoran 2002-11-13
  • 打赏
  • 举报
回复
怎么就这一个字段?
那你的语句可能有问题吧。。
global_boy 2002-11-13
  • 打赏
  • 举报
回复
char(20)
alsoran 2002-11-13
  • 打赏
  • 举报
回复
你的users表的结构是什么样?

56,687

社区成员

发帖
与我相关
我的任务
社区描述
MySQL相关内容讨论专区
社区管理员
  • MySQL
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧