问题
General newbie SQL question probs...
Why doesn't this work - or, what does this mean?
INSERT INTO test_db.dbo.Customers2
SELECT FirstName
FROM jas_test_db.dbo.Customers
WHERE (Customers.FirstName = Firstname)
I get:
Msg 213, Level 16, State 1, Line 2
Column name or number of supplied values does not match table definition.
回答1:
You should supply column name for Customers2:
INSERT INTO test_db.dbo.Customers2(**Firstname**)
SELECT FirstName
FROM jas_test_db.dbo.Customers
WHERE (Customers.FirstName = Firstname)
回答2:
I would recommend to always explicitly specify which columns you want to insert into:
INSERT INTO test_db.dbo.Customers2(FirstName) -- <-- specify the columns you want to insert into!
SELECT FirstName
FROM jas_test_db.dbo.Customers
WHERE (Customers.FirstName = Firstname)
If you don't do this, you have to provide values for all columns, in the exact order in which they are defined in the table
来源:https://stackoverflow.com/questions/22692399/insert-issue-msg-213-level-16-state-1-line-2