Consider the following table:
CREATE TABLE EuropeanCountries(
CountryID int PRIMARY KEY,
CountryName varchar(25)
)
Here’s an INSERT statement without a column list , that works perfectly:
INSERT INTO EuropeanCountriesVALUES (1, ‘Ireland’)
Now, let’s add a new column to this table:
ALTER TABLE EuropeanCountriesADD EuroSupport bit
Now run the above INSERT statement. You get the following error from SQL Server:
Server: Msg 213, Level 16, State 4, Line 1Insert Error: Column name or number of supplied values does not match table definition.
This problem can be avoided by writing an INSERT statement with a column list as shown below:
INSERT INTO EuropeanCountries(CountryID, CountryName)
VALUES (1, ‘England’)
FROM titles
WHERE title LIKE ‘%Computer%’ AND
title LIKE ‘%cook%’
Continues…