我用mysql创建了一个表,并且把ID设置成了主键,和auto_increment,输入不了数据
createtableusers(userIdintprimarykeyauto_increment,usernamevarchar(20),passwdvarchar(...
create table users(
userId int primary key auto_increment,
username varchar(20),
passwd varchar(20),
email varchar(30),
grade int);insert into users values('admin','admin','admin@sufu.com',1)
insert into users values('tester1','tester1','tester1@sofu.com',5)
insert into users values('tester2','tester2','tester2@sofu.com',5)
insert into users values('tester3','tester3','tester3@sofu.com',5)
insert into users values('tester4','tester4','tester4@sofu.com',5)
insert into users values('tester5','tester5','tester5@sofu.com',5)
insert into users values('tester6','tester6','tester6@sofu.com',5)
insert into users values('tester7','tester7','tester7@sofu.com',5)
insert into users values('tester8','tester8','tester8@sofu.com',5)
insert into users values('tester9','tester9','tester9@sofu.com',5)
insert into users values('tester0','tester0','tester0@sofu.com',5);
上面是我的表数据,出现的错误是:ERROR 1136 (21S01): Column count doesn't match value count at row 1 展开
userId int primary key auto_increment,
username varchar(20),
passwd varchar(20),
email varchar(30),
grade int);insert into users values('admin','admin','admin@sufu.com',1)
insert into users values('tester1','tester1','tester1@sofu.com',5)
insert into users values('tester2','tester2','tester2@sofu.com',5)
insert into users values('tester3','tester3','tester3@sofu.com',5)
insert into users values('tester4','tester4','tester4@sofu.com',5)
insert into users values('tester5','tester5','tester5@sofu.com',5)
insert into users values('tester6','tester6','tester6@sofu.com',5)
insert into users values('tester7','tester7','tester7@sofu.com',5)
insert into users values('tester8','tester8','tester8@sofu.com',5)
insert into users values('tester9','tester9','tester9@sofu.com',5)
insert into users values('tester0','tester0','tester0@sofu.com',5);
上面是我的表数据,出现的错误是:ERROR 1136 (21S01): Column count doesn't match value count at row 1 展开
2个回答
展开全部
在MySql中,如果你的insert语句中的表格后面没有加上指明的字段,数据库会默认为你输入的字段与表格的字段安排完全匹配,也就是它把id列也算进来了,所以相当于它需要5个字段的数据,分别是userId,username,passwd,email,grade,这五个字段的数据,但你后面的values括弧中只有四个字段的数据,所以提示列数目不匹配,正确的做法是指明你需要的列,这也是个好习惯:
insert into users(username,passwd,email,grade) values(........)。敬请采纳!
insert into users(username,passwd,email,grade) values(........)。敬请采纳!
2013-08-04
展开全部
nsert into users(这里少字段名) values('admin','admin','admin@sufu.com',1)
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询