APPROX_COUNT_DISTINCT counts distinct values with almost no memory. Tested on 5 million rows, it was within 2.2 percent of the exact count and needed no memory grant, while COUNT(DISTINCT) asked for 436 MB. It was not faster.
SQL SERVER – Interesting Observation of Logon Trigger On All Servers
I created a Logon Trigger to audit every successful login for a client, and one login was recorded several times on different threads. The script and what I saw.
SQL SERVER – Find Hostname and Current Logged In User Name
Connected to many servers in SSMS? HOST_NAME() and SUSER_NAME() show the hostname and current logged in user for any query window.
The Scripts Worth Having on Every Server You Touch
Keep focused DBA scripts for active requests, blocking, table size, index usage, backups, and failed jobs, with clear limits on each result.
SQL SERVER – How to Drop Temp Table – Check Existence of Temp Table
Readers often ask how to check existence of a temp table and how to drop temp table without Msg 2714. My earlier article answers all of these questions.






