What Xactly happens in HTTP Runtime-Asp.Net page processing

Advertisements

How to insert multiple Records into a table? UNION vs UNION ALL

— The context is as simple as inserting multiple records into a table using single insert statement
— This can be acheived using UNION ALL/UNION
–CASE 1 : UNION
insertintoemp
select5,‘XYZ’,‘EEE’,100 UNION
select6,‘ABC’,‘EEE’,100 UNION
select6,‘ABC’,‘EEE’,100
— as the second row and third row are similar, only two records are inserted into the table
— THIS HAPPENS BECAUSE UNION APPLIES DISTINCT ON THE RESULT SET
—————————————————————————————————————–
–CASE 1 : UNION ALL
select5,‘XYZ’,‘EEE’,100 UNIONALL
select6,‘ABC’,‘EEE’,100 UNIONALL
select6,‘ABC’,‘EEE’,100
–3 rows will be inserted to the table as UNION ALL will return the duplicate rows too.
——————————————————————————————————————-
— When to use UNION/UNION ALL
— so if we are sure that result set doesnt contain duplicate rows, its better to UNION ALL as it is
— much faster than UNION, since it doesnt have extra overhead of applying the DISTINCT clause