Insert into ... Select *, how to ignore identity?
Posted
by Haoest
on Stack Overflow
See other posts from Stack Overflow
or by Haoest
Published on 2008-09-23T18:00:56Z
Indexed on
2010/03/17
18:31 UTC
Read the original article
Hit count: 172
sql
|sql-server
I have a temp table with the exact structure of a concrete table T. It was created like this: select top 0 * into #tmp from T
After processing and filling in content into #tmp, I want to copy the content back to T like this: insert into T select * from #tmp
This is okay as long as T doesn't have identity column, but in my case it does. Is there anyways I can ignore the auto-increment identity column from #tmp when I copy to T? My motivation is to avoid having to spell out every column name in the Insert Into list.
EDIT: toggling identity_insert wouldn't work because the pkeys in #tmp may collide with those in T if rows were inserted into T outside of my script, that's if #tmp has auto-incremented the pkey to sync with T's in the first place.
© Stack Overflow or respective owner