Take Care When Scripting Batches for Long Running Query

Source: https://michaeljswart.com/2014/09/take-care-when-scripting-batches/ The Straight Query Suppose we want to remove sales data from FactOnlineSales for the “Worcester Company” whose CustomerKey = 19036. That’s a simple delete statement: DELETE FactOnlineSales WHERE CustomerKey = 19036; This delete statement runs an unacceptably long time. It scans the clustered index and performs 46,650 logical reads and I’m worried about concurrency issues. Naive... » read more

SQLCMD mode in SSMS

SQLCMD mode is a script execution mode that simulates the sqlcmd.exe environment and therefore accepts some commands that are not part of T-SQL language. Just enable SQLCMD mode in SSMS (Query menu -> SQLCMD Mode) and the query will run fine. SSMS can also be configured to automatically enable SQLCMD mode in Tools menu -> Options... » read more