Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Must a column name always be selected?

Author  Topic 

dmilam
Posting Yak Master

185 Posts

Posted - 2011-02-18 : 16:45:23
Or can a default value be set so that it is implied. In other words,



create table #temp (
AssocID int,
PrevEmp bit default 0,
PrevMgr bit default 0
)

insert #temp
select x.ID as 'AssocID'
from table1 x



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

robvolk
Most Valuable Yak

15732 Posts

Posted - 2011-02-18 : 16:50:01
If you're providing fewer values to insert than the total number of columns, yes, you must specify which columns to insert into.

Better yet, you should ALWAYS specify columns in the INSERT INTO clause. Make it a habit, and you'll never have a problem.
Go to Top of Page

dmilam
Posting Yak Master

185 Posts

Posted - 2011-02-18 : 17:14:26
Good to know, thanks!
Go to Top of Page
   

- Advertisement -