Daffy Daffy - 6 months ago 22
SQL Question

Microsoft sql server 2014 Error on insert

When I insert into table with this code I have this error.

INSERT INTO Ridic values(
1, 'Franta' , 'Popkorn' ,
2, 'Slavěna', 'Zíková' ,
3, 'Havel' , 'Bravenec' ,
4, 'Rudolf' , 'Stibor' ,
5, 'Miloš' , 'Vorlíček' ,
6, 'Agáta' , 'Krobotová'
)



Column name or number of supplied values does not match table definition.


But when I try insert only one row everything is OK

INSERT INTO Ridic values(1, 'Franta' , 'Popkorn')


I use SQL server 2014 management studio.
there is table:

create table Ridic
(
UserID int primary key,
Jmeno varchar(10),
Prijmeni varchar(10)
)

Answer

Every set of parenthesis in a values clause refers to a single row. In other words, this statement attempts to insert a single row with 18 columns, which of course fails (the line breaks, like any whitespace are inconsequential). Instead, you should have six sets of parenthesis, each with three columns:

INSERT INTO Ridic VALUES
(1, 'Franta' , 'Popkorn'  ),
(2, 'Slavěna', 'Zíková'   ),
(3, 'Havel'  , 'Bravenec' ),
(4, 'Rudolf' , 'Stibor'   ),
(5, 'Miloš'  , 'Vorlíček' ),
(6, 'Agáta'  , 'Krobotová')