Today, we’re going to look at which database operations can be performed with what’s known as “minimal logging”, which can result in a considerable performance boost. Included is a quick overview of transaction logging and what it’s good for.
Category: Tips
The danger of scripting an Agent job
A fast way to create a duplicate of an SQL Server Agent job is to script it, then modify and run the script. But there’s a pitfall.
Rebuilding a transaction log file
The database’s transaction log file contains, like the name implies, a log of all the transactions happening in the database. If you’ve set your database to the “simple” recovery model, the log is truncated (emptied) at every checkpoint (more or less all the time). In “bulk logged” or “full” recovery model, you’ll have to truncate the log files yourself, by performing a transaction log backup.
So because of this, the log file has to stay in sync with the rest of the database at all times. But what do you do if your log file is lost or corrupted? Luckily, there’s a simple way to recover it.
No explanation required.
I’ll just leave this link right here. Good stuff, no further explanation required.
Analyzing partition usage and skewing
I sometimes want to know how my data is spread across different partitions in a table or index – after all, this can affect performance and storage a great deal, and if the data is really badly skewed, most or all of it could be stuck in a single partition, rendering the partitioning scheme pretty much useless in the first place.
You can use dynamic management views to find out how your data is spread across different partitions, and how those partitions are delimited, in “plain english”. Here’s how!
SSMS: Useful custom keyboard shortcut
I’m sure you already know that you can configure custom keyboard shortcuts in SQL Server Management Studio. Here’s a shortcut that I find really handy, and one that I use frequently.
Instant file initialization
When you create (or grow) the size of a database file, SQL Server will initialize the allocated space on the disk, i.e. fill it with zeroes. If you’re adding a large amount of space to your database file, this operation can take quite some time to complete. But just like there’s a “quick format” in most operating systems, you can allocate large chunks of database file space without initializing it. This is called “Instant file initialization” in the world of SQL Server.
What you didn’t know about GO
The GO keyword isn’t strictly speaking T-SQL – it’s really just a batch terminator used in Management Studio and other tools. But did you know that you can use GO to run a batch multiple times?
Turns out, GO has an optional numeric argument that specifies how many times you want to repeat the batch.
SELECT GETDATE() AS currentDateTime; GO 5
With a little bit of imagination, you could for instance use this to replace dreary old WHILE loops, to populate test values into tables or run a stored procedure multiple times to test performance.
Great article series on statistics
I took some time today to read up on Dale Burnett’s series on statistics in SQL Server. In seven detailed posts, Dale goes through different aspects of how statistics work in SQL Server, and how to use them to your advantage.
If you’re into query optimization, and you’ve got your glasses on, chances are this article is for you.
Cool MERGE features you may not know about
The MERGE statement is a really powerful way to create what’s called “upserts”. In this article, I’ll take a more detailed look at how you can make the best use of MERGE and I’ll also show you some cool tricks I picked up along the way.