All In One Script
MENU

When should I use Cross Apply over Inner Join?

by 1:07:00 AM
undefined
When should I use Cross Apply over Inner Join? What is the main purpose of using CROSS APPLY? I have read (vaguely, through posts on the Internet) that cross apply can be more efficient when selecting over large data sets if you are partitioning. (Paging comes to mind) I also know that CROSS APPLY doesn't require a UDF as the right-table. In most INNER JOIN queries (one-to-many relationships), I could rewrite them to use CROSS APPLY, but they always give me equivalent execution plans. Can anyone give me a good example

Best way to get identity of inserted row?

by 1:02:00 AM
undefined
Best way to get identity of inserted row? What is the best way to get identity of inserted row? I know about @@IDENTITY and IDENT_CURRENT and SCOPE_IDENTITY but don't understand the pros and cons attached to each. Can someone please explain the differences and when I should be using each? Answer: @@IDENTITY returns the last identity value generated for any table in the current session, across all scopes. You need to be careful here, since it's across scopes. You could get a value from a trigger, instead of your current statement.

Instagram