Columns do not hit insertion

0

You're giving an error

  

Column count does not match value count at row 1

    
asked by anonymous 20.08.2017 / 21:25

3 answers

1

You want to insert 4 values in the table, but the table only has 3 columns.

Another thing in column nome varchar (10) will not contain names longer than 10 letters, so increase this length.

As the first column is numeric and sequential, simply create a id column that automatically increments one value with each new insert in the table

 CREATE TABLE IF NOT EXISTS 'livros' (
  'id' INT NOT NULL,
  'nome' VARCHAR(60) NOT NULL,
  'autor' VARCHAR(60) NOT NULL,
  'codliv' INT(2) NOT NULL,
  PRIMARY KEY ('codliv')
 ) ENGINE=MyISAM DEFAULT CHARSET=latin1;

INSERT INTO 'livros' ('nome', 'autor', 'codliv') VALUES
('O grande Conflito', 'Ellen White', 1),
('O capital', 'Karl Marx', 1),
('O Manifesto Comunista', 'Karl Marx', 3),
('A Ideologia Alema', 'Karl Marx', 1);
    
21.08.2017 / 01:34
1

You have 3 columns and you are trying to insert 4 of them, so the error.

Actually this codliv column is weird. If it's a book code it should not be repeated, right?

I think what you want is this code to be the primary key, textual descriptions are bad for primary keys since it is difficult to type equal and may even have repetition. The code of the book should be self-enhanced to ensure oneness. And you do not even need to use it when you insert it, so it's automatically placed by the database.

It would look like this:

CREATE TABLE IF NOT EXISTS 'livros' (
    'codigo' INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
    'nome' VARCHAR(255) NOT NULL,
    'autor' VARCHAR(255) NOT NULL
) ENGINE = MyISAM DEFAULT CHARSET=latin1;

INSERT INTO 'livros' ('nome', 'autor') VALUES
    ('O grande Conflito', 'Ellen White'),
    ('O capital', 'Karl Marx'),
    ('O Manifesto Comunista', 'Karl Marx'),
    ('A Ideologia Alema', 'Karl Marx');

See Running on SQL Fiddle . Also put it in GitHub for future reference .

    
20.08.2017 / 21:29
0

The problem

  

"Column count does not match value count at row 1"

In Portuguese:

  

"The column count does not match the count of values in row 1"

Solution

INSERT INTO livros (codliv , nome , autor ) VALUES (1, 'The Great Controversy', 'Ellen White'), (2, 'The Capital', 'Karl Marx'), (3, 'The Communist Manifesto', 'Karl Marx'), (4, 'The German Ideology', 'Karl Marx');

My suggestion

See it here!

    
20.08.2017 / 22:45