Mar 18, 2014

There are more 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.


Suppose we have created a table by following sql statement

CREATE TABLE tblOrder(
    ntOrderID BIGINT IDENTITY(1,1) NOT NULL,
    vcCustomerName VARCHAR(50) NULL,
    vcDeliveryLocation VARCHAR(100) NULL,
)

Now we are inserting records into it

INSERT INTO tblOrder(
    vcCustomerName,
    vcDeliveryLocation)
VALUES('Greg')

We will get error message :

There are more 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.

Cause: We are inserting two values into the table tblOrder while we have specified only one column that is vcCustomerName in the insert statement

Solution:

INSERT INTO tblOrder(
vcCustomerName,
vcDeliveryLocation
) VALUES('Greg','LA')

Or

INSERT INTO tblOrder(vcCustomerName) VALUES('Greg')

No comments:

Post a Comment