Click here to Skip to main content
15,889,808 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I want to insert data to my table, but i am getting this error below

"
There are fewer columns in the INSERT statement than values specified in the VALUES clause. The number of values in the VALUES clause must match the number of columns specified in the INSERT statement.
".

Name PK nvarchar(50)
Latitute numeric(18,0)
Longitute numeric(18,0)
Description nvarchar(300)

What I have tried:

insert into dbo.Locations(Name, Latitute, Longitute, Description) 
values('Port Elizabeth', 33.9608, 25.6022, 'Port Elizabeth is a city on Algoa Bay in South Africa Eastern Cape Province.',
'Mtata', 31.6067, 28.7781, 'Mthatha, or Umtata, is the main town of the King Sabata Dalindyebo Local Municipality in Eastern Cape province of South Africa',
'East London', 33.0292, 27.8546, 'East London is a city on the Indian Ocean, in South Africa’s Eastern Cape.');
Posted
Updated 9-Mar-20 21:29pm

Please follow the syntax for inserting multiple rows:
INSERT (Transact-SQL) - Inserting multiple rows of data - SQL Server | Microsoft Docs[^]
 
Share this answer
 
The error means exactly what is says: when you write an INSERT statement, the number of columns specified (4 in your case) must exactly match the number of values supplied (12 in your case). If they don't, then the system doesn't know what to do with them.

If you want to insert multiple rows with the same INSERT, then enclose each set of values in brackets, and separate each group with commas:
SQL
INSERT INTO dbo.Locations 
(Name, Latitute, Longitute, Description) 
VALUES(
   ('Port Elizabeth', 33.9608, 25.6022, 'Port Elizabeth is a city on Algoa Bay in South Africa Eastern Cape Province.'),
   ('Mtata', 31.6067, 28.7781, 'Mthatha, or Umtata, is the main town of the King Sabata Dalindyebo Local Municipality in Eastern Cape province of South Africa'),
   ('East London', 33.0292, 27.8546, 'East London is a city on the Indian Ocean, in South Africa’s Eastern Cape.'));


BTW: the correct spellings are "Latitude" and "Longitude".
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900