O'Reilly Forums: error 1136: Column count doesn't match value count at row 1 - O'Reilly Forums

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

error 1136: Column count doesn't match value count at row 1

#1 User is offline   BG1 

  • Active Member
  • PipPipPipPip
  • Group: Members
  • Posts: 124
  • Joined: 24-October 07

Posted 14 November 2007 - 01:01 PM

I'm trying to insert values into my table, but it doesn't seem to work anymore sad.gif I get an error message stating;

"ERROR 1136 (21S01): Column count doesn't match value count at row 1"

I have no clue what it is about, googled for information, but got varying results...

This is my table;

CREATE TABLE toys (toy_id INT(11) NOT NULL AUTO_INCREMENT PRIMARY KEY, toy VARCHAR(20));

Query OK, 0 rows affected (0.33 sec)

INSERT INTO toys (toy_id, toy) VALUES ('', 'hula hoop', '', 'balsa glider');
ERROR 1136 (21S01): Column count doesn't match value count at row 1
0

#2 User is offline   tonyvh37 

  • Advanced Member
  • PipPipPipPipPipPipPipPip
  • Group: Members
  • Posts: 340
  • Joined: 20-May 06
  • Gender:Male
  • Location:Indiana
  • Interests:PC stuff - Gaming to Programming

Posted 14 November 2007 - 06:27 PM

Thats because you have to have two insert statements. The statement you have now is trying to insert ", 'hulahoop,'" into the toy_id column and 'balsa glider' into the toy column. what you need is something like this
INSERT INTO Toys (toy)
    VALUES ('hula hoop') /*not sure what the extra , and "" are for*/
INSERT INTO Toys (toy)
    VALUES ('balsa glider')

You don't need to insert the toy_id because you are using an auto incrementing value and the DB will take care of that. However, you cannot add more than one row into your table with one insert statement. A new row = a new insert statement. Hopefully that helps.
0

#3 User is offline   louisc 

  • Active Member
  • PipPipPipPip
  • Group: Members
  • Posts: 112
  • Joined: 12-February 07
  • Interests:human-machine interfaces

Posted 14 November 2007 - 09:36 PM

BG1, you have a slight syntax problem. When you want to insert multiple rows, you need to write the statement a little differently. What you should have done is this:
INSERT INTO toys (toy_id, toy) VALUES ('', 'hula hoop'), ('', 'balsa glider');

There are a few alternatives. Instead of using the somewhat confusing empty quotes, you can use DEFAULT like this:
INSERT INTO toys (toy_id, toy) VALUES
(DEFAULT, 'hula hoop'),
(DEFAULT, 'balsa glider');

Or even better, let toy_id take care of itself and write this:
INSERT INTO toys (toy) VALUES
('hula hoop'),
('balsa glider');

0

#4 User is offline   BG1 

  • Active Member
  • PipPipPipPip
  • Group: Members
  • Posts: 124
  • Joined: 24-October 07

Posted 15 November 2007 - 12:27 AM

I should stop working on this late at night I guess, 'cause this was a bit obvious... :oops:

Anyways, thanks again for helping me out, I was pulling hair out of my skull allready wink.gif
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users