开发者

Temp record Insertion technique

开发者 https://www.devze.com 2023-04-07 07:13 出处:网络
I am using sql s开发者_Python百科erver 2008. I have to insert records in temporary table using multiple select statements like below.

I am using sql s开发者_Python百科erver 2008. I have to insert records in temporary table using multiple select statements like below.

Insert into #temp
Select a From TableA

Insert into #temp
Select a From TableB

Insert into #temp
Select a From TableC

Insert into #temp
Select a From TableD

OR

Insert Into #temp
Select A From
(
    Select A from TableA
    Union
    Select B From TableB
    Union
    Select B From TableC
)K

Please advice which approach should be best or any other and Why?


The two techniques you present are not interchangeable. The UNION operation will remove duplicate values while the individual INSERT operations will not. To get identical results, you'd need to use UNION ALL.

0

精彩评论

暂无评论...
验证码 换一张
取 消