• 全部
  • 问答

添加纪录问题;

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
请问该如何解决?


:)
...全文
7 点赞 收藏 17
写回复
17 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
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表的结构是什么样?
回复
发帖
MySQL
创建于2007-09-28

5.4w+

社区成员

MySQL相关内容讨论专区
申请成为版主
帖子事件
创建了帖子
2002-11-13 09:27
社区公告
暂无公告