Skip to content
Advertisement

Insert query: Column name or number of supplied values does not match table definition

This is a table that auto increments the ID, takes the time input, and sets the default of the total column as zero and the date column with getdate()

CREATE TABLE OrderPlaced (
    OrderID bigint IDENTITY(1,1) PRIMARY KEY,
    PlacedAt time NOT NULL,
    PlacedOn DATE NOT NULL default getdate(),
    Total MONEY default 0
)

So the only value that I have to insert is the time.

insert into OrderPlaced values ('13:40'); 

However on insertion SQL Server gives me this error:

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

Advertisement

Answer

You need to specify the column name as well, like this:

INSERT INTO table_name (column1, column2, column3, ...) VALUES (value1, value2, value3, ...);

So it will be like this:

insert into OrderPlaced values ('13:40');

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement