August 4, 2009 at 7:25 pm
Hi All,
In SQL Server, Can we load data into two table from a single table in a single shot?
something like we do it as below:
select * into
IS there any way to achieve this?
Thanks in advance.
August 4, 2009 at 8:51 pm
Sorry, you can't insert data into two separate tables with one insert statement. You'll need to do it in two steps.
August 5, 2009 at 6:29 am
Thanks Lynn.
August 5, 2009 at 6:45 am
You can do it by using the OUTPUT clause...
CREATE TABLE a (id int, descr varchar(255))
GO
CREATE TABLE b (id int, descr varchar(255))
GO
INSERT a output inserted.id, inserted.descr into b values(1,'Description')
select * from a
select * from b
August 5, 2009 at 7:01 am
One warning about the output clause, it can only contain columns that were inserted into the primary table (and calculated columns based on those columns). It will not allow you "split" a single input table.
__________________________________________________
Against stupidity the gods themselves contend in vain. -- Friedrich Schiller
Stop, children, what's that sound? Everybody look what's going down. -- Stephen Stills
August 5, 2009 at 11:29 am
Thanks Guys! 🙂
Viewing 6 posts - 1 through 5 (of 5 total)
You must be logged in to reply to this topic. Login to reply