SQL Clone
SQLServerCentral is supported by Redgate
Log in  ::  Register  ::  Not logged in

How Should It Work?

I was following a debate on the new Merge syntax in SQL Server 2008 with interest. It was somewhat of a debate about hot things should work, what happens with NULLs, etc. Now I don't want to recreate it here, but one thing was interesting to me. What would you expect from this?


Merge (select top 1 * from xxx where yyy)

 when matched ....

 when not matched ...



How many rows should be inserted? Would the top 1 that matched each section be inserted? I'd think only 1 row would be processed. To me the MERGE statement should only have 1 row input to it and whichever section it matched would process it.

 Is this not intuitive to anyone else?

The Voice of the DBA

Steve Jones is the editor of SQLServerCentral.com and visits a wide variety of data related topics in his daily editorial. Steve has spent years working as a DBA and general purpose Windows administrator, primarily working with SQL Server since it was ported from Sybase in 1990. You can follow Steve on Twitter at twitter.com/way0utwest


No comments.

Leave a Comment

Please register or log in to leave a comment.