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

Backup, file manipulation operations (such as ALTER DATABASE ADD FILE) and encryption changes on a database must be serialized

Issue: Getting the following when trying to shrink the database. Error: Could not adjust the space allocation for file ‘xxxxxxxxx’.Backup, file manipulation operations (such as ALTER DATABASE ADD FILE) and encryption changes on a database must be serialized. Reissue the statement after the current backup or file manipulation operation is completed. (Microsoft SQL Server, Error:... » read more

Table Partitioning in SQL Server – Partition Switching

https://pragmaticworks.com/blog/table-partitioning-in-sql-server-partition-switching Partition switching moves entire partitions between tables almost instantly. It is extremely fast because it is a metadata-only operation that updates the location of the data, no data is physically moved. New data can be loaded to separate tables and then switched in, old data can be switched out to separate tables and then archived or purged.... » read more

Advantages of Database Partition

https://blog.coeo.com/five-cool-things-you-can-do-using-partitioning Move files to another location without affecting the availability of the database. Rebuild part of our data using different compression/fill factor settings. Setting part of our data to be READ_ONLY. Quickly remove old data without incurring in high log usage. … Partial backups and restores.