SQL Saturday #381 – Richmond, VA

SQL Saturday #381 – Richmond, VA

Last Saturday I attended #SQLSATRVA, which was SQL Saturday #381. It was a blast! The day started off with the usual registration process. Thankfully, I remembered to print out and cut my SpeedPass in advance. The line to use the…

Running PowerShell in a SQL Agent Job

Running PowerShell in a SQL Agent Job

When creating a SQL Agent Job to execute a PowerShell script, you have to decide which way that you want the PowerShell to run. Depending upon which version of SQL Server that you are using and which job step type that you…

Stored Procedures, Dynamic SQL and Execution Plans

Stored Procedures, Dynamic SQL and Execution Plans

Question If stored procedure execution plans are cached once and then reused, what version of the execution plan is cached for stored procedures that have dynamically created queries? Answer Dynamic SQL queries and stored procedures generate separate execution plans and…

Transact-SQL COUNT(*) vs COUNT(column) vs COUNT(1)

Transact-SQL COUNT(*) vs COUNT(column) vs COUNT(1)

I have heard a few different beliefs regarding how to write T-SQL queries when using the COUNT() function. Never use COUNT(*), it must read all columns and cause unnecessary reads. Always use COUNT(1) because, generally, the primary key is the…

Derik Hammer Presents, Fun with DATETIME

Derik Hammer Presents, Fun with DATETIME

As my regular readers might have noticed, I get a lot of my ideas for this blog from my daily life. This post is no different. I was helping a co-worker troubleshoot an incorrect result-set. After we had corrected the…

Paul Randal, please mentor me

Today I’m going to go a bit off schedule and deviate from my usual technical content. Paul Randal (b | t) is the owner of SQLSkills which is a consulting and training organization. A few weeks ago Red-Gate announced their Tribal Awards…

Optimizing for unknown and NULLs

Optimizing for unknown and NULLs

The other day I had an interesting conversation about something that sounds counter-intuitive. If NULL means unknown or missing, then does OPTIMIZE FOR UNKNOWN mean to optimize for NULL? Let’s take a step back for a moment and put this…

Active sessions and block duration

Active sessions and block duration

As a DBA, we all need the ability to take a quick glance at the currently active processes on our servers. A lot of times we do this during a problem such as transaction blocking. The first tool that normally…