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
 Help with simple select into

Author  Topic 

Bjcascone
Starting Member

37 Posts

Posted - 2009-09-17 : 12:53:37
I have 2 tables that are identical and i want to union them as one. I am not sure if a Select into or an insert into would work best in this situation. They are both very small tables. I attempted to select into an existing table and that did not work. and i have an Identity clause that will not allow me to do an insert into.

Thank you
Brian

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2009-09-17 : 12:58:10
set identity_insert on
insert table_3
select * from table_1
union -- or union all if duplicates are ok
select * from table_2
set identity_insert off


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

Bjcascone
Starting Member

37 Posts

Posted - 2009-09-17 : 13:07:05
Im sorry i said union and that is not what i need to do. I meant to say insert into.
I wrote a simple select into and I get an error message saying that there is already an object with that name. Can I not use select into for inserting data into an existing table? I also tried an insert into and it does not allow me to keep the Identity clause in the insert statement.
Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2009-09-17 : 13:12:26
Huh?
My posted solution should do the following:
- allow inserts for identity column
- insert into an existing table (here table_3) what select... union select... returns from both older tables(table_1,table_2)
- disallow inserts for identity column


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page
   

- Advertisement -