ABpositive
ABpositive

Reputation: 303

Error on INSERT statement: "VALUE is not valid at this position"

VALUE is not valid at this position

The error is on VALUES within the INSERT statement. It states it is not supported within this version. Does that mean i require an update or is my syntax wrong?

create schema Cleudo;
USE CLEUDO;

create table Victim(
   Vic_ID INT NOT NULL AUTO_INCREMENT,
   Vic_Title VARCHAR(10) NOT NULL,
   Vic_Name VARCHAR(30) NOT NULL,
   Vic_Room VARCHAR(30) NULL,
   Vic_TOD VARCHAR(5) NULL,
   Vic_Weapon VARCHAR(30) NULL,
   PRIMARY KEY ( VIC_ID )
);

INSERT INTO Victim VALUES ('Miss','Scarlet','Library','10:45','candle-Stick');

Upvotes: 0

Views: 149

Answers (2)

user11092642
user11092642

Reputation:

You are getting this error because the number of columns are not the same, so you need to change your query to this:

INSERT INTO Victim(Vic_Title,Vic_Name,Vic_Room,Vic_TOD,Vic_Weapon) VALUES ('Miss','Scarlet','Library','10:45','candle-Stick');

In case you want to specify the Vic_ID value you can try this query below instead:

INSERT INTO Victim VALUES (NULL,'Miss','Scarlet','Library','10:45','candle-Stick')

Upvotes: 0

GMB
GMB

Reputation: 222582

When I run your code, I get the following error:

Column count doesn't match value count at row 1

This is happening because you are not giving a value to table Vic_ID (which makes sense, because it is auto-incremented). To avoid the error, you need to enumerate the target columns, like so:

INSERT INTO Victim (Vic_Title, Vic_Name, Vic_Room, Vic_TOD, Vic_Weapon)
VALUES ('Miss','Scarlet','Library','10:45','candle-Stick');

Demo on DB Fiddle

Upvotes: 1

Related Questions