Skip to content

Clive Roberts

SQL Server DBA

Menu
  • Setup
  • Performance
  • Health Check
  • Troubleshooting
  • T-SQL
  • Patches
  • News
  • Audit
  • Projects

Category: Setup

Encrypting SQL Server Connections

November 26, 2026
| No Comments
| Question of the Day, Setup, SQL Server
Encrypting SQL Server Connections: the T-SQL from this post in SQL Server Management Studio with its results

Applies to SQL Server 2019, 2022 and 2025. SQL Server connection encryption protects the data travelling between an application and the server: the queries, the results and anything else on the wire. It’s separate from TDE or backup encryption, which protect data at rest. I check it on every server I look after, because the…

Read More »

Posted in Question of the Day, Setup, SQL Server

SQL Server Installs Tested Before and After with dbatools and Pester

November 23, 2026
| No Comments
| Setup, SQL Server
SQL Server Setup: SQL Server Installs Tested Before and After with dbatools and Pester

A dbatools SQL Server install wrapped in Pester tests: the server is proved ready before anything is installed, and the instance is proved configured afterwards. With a second data centre settings file and the bugs I fixed.

Read More »

Posted in Setup, SQL Server

SQL Server Certificate Expiry

November 18, 2026
| 1 Comment
| Question of the Day, Setup, SQL Server
SQL Server Certificate Expiry: the T-SQL from this post in SQL Server Management Studio with its results

Applies to SQL Server 2019, 2022 and 2025. Every SQL Server certificate has an expiry date, whether or not you gave it one. What surprises people is how little SQL Server certificate expiry actually matters for most of what certificates do inside the database engine, and how much it matters for the one or two…

Read More »

Posted in Question of the Day, Setup, SQL Server 1 Comment

Moving the SQL Server Error Log

November 16, 2026
| No Comments
| Question of the Day, Setup, SQL Server
Moving the SQL Server Error Log: the T-SQL from this post in SQL Server Management Studio with its results

Applies to SQL Server 2019, 2022 and 2025. The SQL Server error log location is set when the service starts, by the -e startup parameter. By default it sits under the instance’s MSSQL\Log folder on the system drive, and I usually move it when a build puts that folder somewhere small or awkward. The move…

Read More »

Posted in Question of the Day, Setup, SQL Server

Backing Up the Database Master Key

November 10, 2026
| 1 Comment
| Question of the Day, Setup, SQL Server
Backing Up the Database Master Key: the T-SQL from this post in SQL Server Management Studio

Applies to SQL Server 2019, 2022 and 2025. If a database uses certificates or symmetric keys, it has a database master key (DMK), and you should back up the database master key as soon as it’s created. It’s a two-line job, but the reason it matters is a little different from what most people assume,…

Read More »

Posted in Question of the Day, Setup, SQL Server 1 Comment

Fixed Server Roles in SQL Server

October 28, 2026
| No Comments
| Question of the Day, Setup, SQL Server
Fixed Server Roles in SQL Server: the T-SQL from this post in SQL Server Management Studio with its results

Applies to SQL Server 2019, 2022 and 2025. Fixed server roles are the built-in groups SQL Server gives you for instance-wide permissions. You add a login to a role and it picks up everything that role can do. They’re quick to use, which is exactly why they get overused. Since SQL Server 2022 there are…

Read More »

Posted in Question of the Day, Setup, SQL Server

SQL Server Trace Flags

October 18, 2026
| No Comments
| Setup
SQL Server Setup: SQL Server Trace Flags

SQL Server trace flags change how the engine behaves under the hood. I mostly use them to get more detail when troubleshooting, to quieten the error log, or to switch on an optimiser fix. Some are documented, many are not, so test them before they go anywhere near production. What They Do: Modify query optimiser…

Read More »

Posted in Setup

PowerShell and dbatools

October 17, 2026
| No Comments
| Setup
SQL Server Setup: PowerShell and dbatools

PowerShell and dbatools together are the quickest way I know to check many SQL Servers at once. dbatools is a free, community-built PowerShell module with several hundred commands for SQL Server administration, and it is most useful for daily checks across servers and for repeatable migrations. Run it from an admin workstation or jump server,…

Read More »

Posted in Setup

Backup to URL and Backup Encryption

October 16, 2026
| No Comments
| Setup
SQL Server Setup: Backup to URL and Backup Encryption

Tested on SQL Server 2022: backup encryption end to end (including restoring on a server without the certificate), and backup to URL (credential, backup, verify, restore, encrypted and striped backups) against Microsoft’s Azure storage emulator. Not yet tried against a real Azure storage account. Backup encryption Native backup encryption (SQL Server 2014 onwards) encrypts the…

Read More »

Posted in Setup

Failover Cluster Instances and Distributed Availability Groups

October 16, 2026
| No Comments
| Setup
SQL Server Setup: Failover Cluster Instances and Distributed Availability Groups

Tested on SQL Server 2022: the distributed availability group (create, join, automatic seeding and the health check) worked between two test instances, and the FCI status queries run. The FCI PowerShell commands and failover have since been tested on a Windows Server failover cluster. Failover Cluster Instances (FCI) An FCI is one SQL Server instance…

Read More »

Posted in Setup

Building an Availability Group

October 16, 2026
| 1 Comment
| Setup
SQL Server Setup: Building an Availability Group

Tested on SQL Server 2022 (two test instances): the endpoints, CREATE and JOIN, automatic seeding, the readable secondary and a manual failover and failback all worked. Windows-authenticated endpoints, the listener and automatic failover have since been tested on a Windows Server failover cluster. This post covers building an Availability Group (AG) from scratch on Windows…

Read More »

Posted in Setup 1 Comment

Migrating SQL Server to Azure

October 15, 2026
| No Comments
| Setup
SQL Server Setup: Migrating SQL Server to Azure

Moving SQL Server to Azure is mostly a matter of picking the right target and finding the blockers early. The copying is the easy part. This is the order I work in. 1. Pick the target first Everything else depends on this choice, so make it before anything else. SQL Server on an Azure VM:…

Read More »

Posted in Setup

Azure SQL Options

October 15, 2026
| No Comments
| Setup
SQL Server Setup: Azure SQL Options

“Put it in Azure” can mean five different things for SQL Server, and they behave very differently. This is how I tell them apart: 1. Azure SQL Database Platform as a Service (PaaS). Fully managed, scalable, and suited to modern cloud applications. Supports single databases or elastic pools (multiple databases sharing resources). Built-in high availability,…

Read More »

Posted in Setup

Upgrading SSRS 2005 to 2012 (Quick and Dirty)

October 15, 2026
| No Comments
| Setup
SQL Server Setup: Upgrading SSRS 2005 to 2012 (Quick and Dirty)

This is the quick way to move Reporting Services from a 2005 server to a new 2012 server, keeping all the reports, data sources and subscriptions. The idea is simple: build a clean 2012 instance, bring the old report databases across, and give it the old encryption key. Step 1: Install and configure SSRS 2012…

Read More »

Posted in Setup

Migrating a Reporting Services Installation (Native Mode)

October 15, 2026
| No Comments
| Setup
SQL Server Setup: Migrating a Reporting Services Installation (Native Mode)

This covers moving a native mode Reporting Services install (2008, 2008 R2, 2012 or 2014) to a new SQL Server 2016 Reporting Services instance, instead of upgrading in place. I migrate rather than upgrade when the hardware is changing, when the server can’t be down for long, or when something blocks an in-place upgrade. The…

Read More »

Posted in Setup

Enabling Change Tracking: Good and Bad Points

October 15, 2026
| No Comments
| Setup
SQL Server Setup: Enabling Change Tracking: Good and Bad Points

Change Tracking records which rows in a table have changed (by primary key) and whether each was an insert, update or delete, so an application or ETL process can sync only what has changed. It does not store old or new values; the reader joins back to the table for the current values. It is…

Read More »

Posted in Setup

Adding an Article to a Publication

October 15, 2026
| No Comments
| Setup
SQL Server Setup: Adding an Article to a Publication

SQL Replication To add an article after a publication is created On the Articles page of the Publication Properties – <Publication> dialogue box, clear the Show only checked objects in the list check box. This allows you to see the unpublished objects in the publication database. Select the check box next to each article you…

Read More »

Posted in Setup

SQL Server Replication: Setup, Types and Pitfalls

October 15, 2026
| No Comments
| Setup
SQL Server Setup: SQL Server Replication: Setup, Types and Pitfalls

Setting up SQL replication involves several steps to make sure data is consistently copied from one database to another. Here’s a basic guide to get you started: Prepare the Environment Make sure you have SQL Server installed on both the publisher and subscriber servers. You’ll also need SQL Server Management Studio (SSMS). Configure the Distributor…

Read More »

Posted in Setup

Generating the SPNs (Kerberos)

October 13, 2026
| No Comments
| Setup
SQL Server Setup: Generating the SPNs (Kerberos)

To allow SQL Server to auto-generate the Service Principal Names (SPNs) needed, you can provide the proper permissions to the SQL Service Account. The steps: Grant Permissions: Make sure the SQL Service Account has the necessary permissions to register SPNs. This can be done by adding the account to the Active Directory group that has…

Read More »

Posted in Setup

Random Password Generator

October 13, 2026
| No Comments
| Setup
SQL Server Setup: Random Password Generator

RAND() is not cryptographically secure and this script is limited to 10 characters. Fine for test data; for real service account passwords use the password manager’s generator. DECLARE @length smallint =10 ,@id INT ,@pwd VARCHAR (10) = ” IF @length >10 begin raiserror (‘Password Length too long’,16,1,0) return end WHILE LEN(@pwd) < @length BEGIN SELECT…

Read More »

Posted in Setup

Login Failures (Error 18456)

October 13, 2026
| No Comments
| Setup
SQL Server Setup: Login Failures (Error 18456)

The client only sees ‘Login failed for user’. The reason is in the SQL Server error log, as a state number. EXEC sp_readerrorlog 0, 1, N’Login failed’; What the state means State 2 or 5: the login does not exist. Wrong name, or a Windows user who is not in any group that has a…

Read More »

Posted in Setup

Replicating SQL Server Logins with Their SIDs

October 13, 2026
| 1 Comment
| Setup
SQL Server Setup: Replicating SQL Server Logins with Their SIDs

To replicate SQL Server logins from one server to another: including their SIDs (Security Identifiers), you need a script that extracts login details from the source server and generates CREATE LOGIN statements for the target server. This ensures that database users remain mapped correctly, avoiding orphaned users. Here’s a full script to do just that:…

Read More »

Posted in Setup 1 Comment

Orphaned SQL Logins

October 13, 2026
| No Comments
| Setup
SQL Server Setup: Orphaned SQL Logins

An orphaned SQL login occurs when a SQL Server login exists at the server level, but its corresponding database user is no longer properly mapped within a specific database. This often happens after restoring a database from another server or detaching and reattaching a database. Why It Happens Each SQL login has a SID (Security…

Read More »

Posted in Setup

FILESTREAM

October 13, 2026
| No Comments
| Setup
SQL Server Setup: FILESTREAM

To configure FILE-STREAM in SQL Server, follow these steps. FILE-STREAM allows you to store large binary data (like documents, images, videos) in the file system while maintaining transactional consistency with the database. Step-by-Step: Enable and Configure FILE-STREAM 1. Enable FILE-STREAM at the SQL Server Instance Level Open SQL Server Configuration Manager. Go to SQL Server…

Read More »

Posted in Setup

SQL Server Audit

October 13, 2026
| 1 Comment
| Setup
SQL Server Setup: SQL Server Audit

SQL Server Audit records who did what. A server audit is the destination (a file or the Windows log). A server audit specification captures instance-level events such as failed logins and permission changes; a database audit specification captures actions in one database, such as reads or changes to a sensitive table. I use SQL Server…

Read More »

Posted in Setup 1 Comment

Data Obfuscation and Masking

October 12, 2026
| No Comments
| Setup
SQL Server Setup: Data Obfuscation and Masking

Masking data is the usual way to protect sensitive information outside production, in development and test copies. Which approach to use depends on what you need: 1. Data Masking Techniques These are used to hide sensitive data while maintaining its format and usability. Static Data Masking Done once and stored in the database. Example: Replace…

Read More »

Posted in Setup

TDE: Backing Up the Certificate

October 12, 2026
| 2 Comments
| Setup
SQL Server Setup: TDE: Backing Up the Certificate

With Transparent Data Encryption, a backup can only be restored on a server that has the certificate and its private key. If the certificate is lost, every backup of that database is unreadable. Step 1: Which databases use TDE, and which certificate SELECT DB_NAME(dek.database_id) AS database_name, dek.encryption_state, — 3 = encrypted c.name AS certificate_name, c.expiry_date,…

Read More »

Posted in Setup 2 Comments

Encryption

October 12, 2026
| No Comments
| Setup
SQL Server Setup: Encryption

SQL Server offers Transparent Data Encryption (TDE) and Always Encrypted as its two main database encryption features. 1. Transparent Data Encryption (TDE) Purpose: Encrypts the entire database at rest (data files, log files, backups). Key Features: Protects against unauthorised access to physical files. Encryption is transparent to applications. Uses a Database Encryption Key (DEK) stored…

Read More »

Posted in Setup

Server Build Checklist

October 10, 2026
| No Comments
| Setup
SQL Server Setup: Server Build Checklist

Settings to apply on every new SQL Server instance before it goes live. The values below are starting points; adjust them for the server. Instance settings EXEC sp_configure ‘show advanced options’, 1; RECONFIGURE; EXEC sp_configure ‘max server memory (MB)’, 28672; — example for a 32 GB server EXEC sp_configure ‘max degree of parallelism’, 8; EXEC…

Read More »

Posted in Setup

Database Snapshots

October 10, 2026
| No Comments
| Setup
SQL Server Setup: Database Snapshots

A database snapshot is created with the CREATE DATABASE statement. A database snapshot provides a read-only, static view of a database, which can be useful for reporting, auditing, and data recovery purposes. Here is an example of how you might create a database snapshot: CREATE DATABASE Audit_Snapshot ON ( NAME = logical_file_name, FILENAME = ‘os_file_name’…

Read More »

Posted in Setup

Moving TempDB

October 9, 2026
| 2 Comments
| Setup
SQL Server Setup: Moving TempDB

Moving TempDB to another drive or folder is a routine job, but there are a couple of traps. The steps: Identify the Current Location: SELECT name, physical_name AS CurrentLocation FROM sys.master_files WHERE database_id = DB_ID(N’tempdb’); Specify the New Location: USE master; GO ALTER DATABASE tempdb MODIFY FILE (NAME = tempdev, FILENAME = ‘new_path\tempdb.mdf’); ALTER DATABASE…

Read More »

Posted in Setup 2 Comments

Database Mail Setup and Troubleshooting

October 9, 2026
| 3 Comments
| Setup
SQL Server Setup: Database Mail Setup and Troubleshooting

Database Mail is how SQL Server sends email: job failure notifications, alerts to operators, and reports from sp_send_dbmail. It sends through your SMTP server using a profile and one or more accounts, and it queues mail through Service Broker in msdb, which is where most problems turn up. Below is the setup, a test, and…

Read More »

Posted in Setup 3 Comments

Log Shipping

October 8, 2026
| No Comments
| Setup
SQL Server Setup: Log Shipping

Log shipping backs up the transaction log on the primary, copies the files to a secondary and restores them there on a schedule. It runs as three SQL Agent jobs: the backup job on the primary, and the copy and restore jobs on the secondary. It is available in Standard Edition. Good points and limitations…

Read More »

Posted in Setup

Quorum Failure

October 8, 2026
| No Comments
| Setup
SQL Server Setup: Quorum Failure

Quorum failure is a more complicated situation that is generally caused by persistent communications failure or by the problematic configuration of cluster nodes. Quorum failure must be resolved manually by performing the following steps: Start the Windows Server Failover Cluster by using forced quorum on a single node. You do this by choosing Force Cluster…

Read More »

Posted in Setup

Availability Group Health Troubleshooting

October 8, 2026
| No Comments
| Setup
SQL Server Setup: Availability Group Health Troubleshooting

Use this when an availability database shows Not Synchronizing or Suspended, when the AG dashboard shows a warning, or when log_reuse_wait_desc is AVAILABILITY_REPLICA (see Transaction Log Full). Step 1: State of every replica SELECT ag.name AS ag_name, ar.replica_server_name, ars.role_desc, ars.connected_state_desc, ars.synchronization_health_desc FROM sys.dm_hadr_availability_replica_states ars JOIN sys.availability_replicas ar ON ars.replica_id = ar.replica_id JOIN sys.availability_groups ag ON…

Read More »

Posted in Setup

Suspending and Resuming Data Movement

October 8, 2026
| No Comments
| Setup
SQL Server Setup: Suspending and Resuming Data Movement

How to suspend data movement in SQL Server Always On Availability Groups The process to suspend data movement is the same from primary and secondary replica; however, you need to be connected to the appropriate instance. Connect to the SQL in SSMS, go to Always On Availability Groups-> Availability Groups-> Availability Databases. Right-click on the…

Read More »

Posted in Setup

Adding a Database to an Availability Group

October 8, 2026
| No Comments
| Setup
SQL Server Setup: Adding a Database to an Availability Group

In the context of SQL Server Always On Availability Groups (AGs), automatic seeding refers to the process where the primary replica automatically transfers a database to secondary replicas without requiring manual backup and restore. While there aren’t “types” of automatic seeding per se, there are different methods for adding databases to AGs, and automatic seeding…

Read More »

Posted in Setup

Basic vs Advanced High Availability

October 7, 2026
| No Comments
| Setup
SQL Server Setup: Basic vs Advanced High Availability

In SQL Server (and other database systems), High Availability (HA) ensures that your databases remain accessible and operational even in the event of hardware failures, software issues, or planned maintenance. The difference between basic and advanced HA lies in the features, flexibility, and scalability they offer. Basic High Availability Basic HA solutions are typically simpler…

Read More »

Posted in Setup

Disaster Recovery Planning

October 7, 2026
| No Comments
| Setup
SQL Server Setup: Disaster Recovery Planning

Disaster recovery plan objectives The key objective of a disaster recovery plan is to detail the key activities required to reinstate the critical IT services within the agreed recovery objectives. The most effective start point for any DR plan is the ‘declaration of a disaster’ once an incident has been deemed serious enough that ‘forward…

Read More »

Posted in Setup

Backup and Restore with T-SQL

October 7, 2026
| No Comments
| Setup
SQL Server Setup: Backup and Restore with T-SQL

Scripted backups are repeatable and leave a record of exactly what was run. Always use CHECKSUM so damaged pages are caught when the backup is taken, not when you need to restore it. Full backup BACKUP DATABASE [YourDB] TO DISK = N’\\BackupServer\SQLBackups\YourDB\YourDB_FULL_20261002.bak’ WITH CHECKSUM, COMPRESSION, STATS = 10; Differential backup BACKUP DATABASE [YourDB] TO DISK…

Read More »

Posted in Setup

Restoring a Database to a New Location

October 7, 2026
| No Comments
| Setup
SQL Server Setup: Restoring a Database to a New Location

To move databases to a new server due to old hardware, failed hardware, failed drives, etc. You have two options you could use to carry out this task: SQL Server Management Studio (GUI) T-SQL (Command line) The method I prefer is T-SQL. It is simple and easy and avoids clicking the mouse all over the…

Read More »

Posted in Setup

Restoring a Full Database Backup (SSMS)

October 7, 2026
| 2 Comments
| Setup
SQL Server Setup: Restoring a Full Database Backup (SSMS)

This topic explains how to restore a full database backup. Important: Under the full or bulk-logged recovery model, before you can restore a database in SQL Server Management Studio, you must back up the active transaction log (known as the tail of the log). To restore a database that is encrypted, you must have access…

Read More »

Posted in Setup 2 Comments

Backing Up and Restoring a Database

October 7, 2026
| No Comments
| Setup
SQL Server Setup: Backing Up and Restoring a Database

Introduction When upgrading applications we often move the database from one server to another by taking a back-up and restoring onto the new server. Change Process Take a Back-up of the database Create a copy of the database on the new server Technical Process Step 1 To perform a one-off full backup of a database…

Read More »

Posted in Setup

Regain sysadmin access to SQL Server (2016–2022) when no login works

November 9, 2017
| No Comments
| Setup, SQL Server
SQL Server Setup: Regain sysadmin access to SQL Server (2016–2022) when no login works

It happens more often than you’d think. A server is joined to a domain, or taken off one, or the DBA who set it up leaves, and suddenly nobody can get into SQL Server as sysadmin. You don’t need a password to fix it. Anyone in the server’s local Administrators group can get back in…

Read More »

Posted in Setup, SQL Server

sp_who3: sp_who2 with SQL Text, Waits and Reads

October 31, 2016
| No Comments
| Setup, Troubleshooting
SQL Server Troubleshooting: sp_who3: sp_who2 with SQL Text, Waits and Reads

sp_who3 works like sp_who2 but adds the running SQL text, wait type, reads, writes and elapsed time, using the sys.dm_exec_sessions and sys.dm_exec_requests DMVs. It only lists sessions that are running a request. For much more detail use Adam Machanic’s sp_WhoIsActive. Tested on SQL Server 2017 and 2025 and safe to run more than once. USE…

Read More »

Posted in Setup, Troubleshooting

Which Trace Flags to Keep on SQL Server 2016–2022

October 31, 2016
| No Comments
| Setup
SQL Server Setup: Which Trace Flags to Keep on SQL Server 2016–2022

Which trace flags to use on SQL Server 2016 to 2022. Most of the old “always on” flags (1117, 1118, 2371, 4199, 9481) are now default behaviour or a per-database setting, so this script turns them off and keeps only the ones still worth having. Tested on SQL Server 2017 and 2025. — Trace flags…

Read More »

Posted in Setup

Weekly DBCC CHECKDB Agent Jobs (Ola Hallengren)

October 31, 2016
| 1 Comment
| Setup
SQL Server Setup: Weekly DBCC CHECKDB Agent Jobs (Ola Hallengren)

Creates two SQL Agent jobs, DatabaseIntegrityCheck – SYSTEM_DATABASES and DatabaseIntegrityCheck – USER_DATABASES, which run Ola Hallengren’s DatabaseIntegrityCheck (DBCC CHECKDB) from the SQLDBA database every Sunday at 6 am and email DBA_Alerts if they fail. Install the Maintenance Solution in SQLDBA first (see the Database_Integrity_Check post). Run it in SSMS normal mode, not SQLCMD mode. Tested…

Read More »

Posted in Setup 1 Comment

Database Integrity Check

October 31, 2016
| 1 Comment
| Setup
SQL Server Setup: Database Integrity Check

A database integrity check runs DBCC CHECKDB to find corruption before it finds you: damaged pages are far easier to deal with when you spot them early and still have a clean backup to restore from. I run it weekly with Ola Hallengren’s DatabaseIntegrityCheck, and Microsoft’s DBCC CHECKDB documentation covers what the checks do. Installing…

Read More »

Posted in Setup 1 Comment

Weekly Index Maintenance Agent Job (Ola Hallengren)

October 31, 2016
| 1 Comment
| Setup
SQL Server Setup: Weekly Index Maintenance Agent Job (Ola Hallengren)

This index job script creates the SQL Agent job IndexOptimize – USER_DATABASES, which runs Ola Hallengren’s IndexOptimize from the SQLDBA database every Friday at 7 pm and emails DBA_Alerts if it fails. Install the Maintenance Solution in SQLDBA first (see the Index Optimize post) and create the operator (see Create_Operator_and_Standard_Alerts). Run it in SSMS normal…

Read More »

Posted in Setup 1 Comment

Create Backup Objects and Jobs

October 31, 2016
| No Comments
| Setup
SQL Server Setup: Create Backup Objects and Jobs

This script will create backup objects and jobs in a SQLDBA database: a config table, a backup log, an exclusion list, the backup, copy, archive and retention procedures, and SQL Agent jobs for full, differential, log and clean-up. Backups are written locally, then copied to a central share. Change \\backupserver\ to your backup share. Tested…

Read More »

Posted in Setup

Index Optimize

October 31, 2016
| 1 Comment
| Setup
SQL Server Setup: Index Optimize

Index Optimize is Ola Hallengren’s IndexOptimize procedure, which rebuilds or reorganises indexes only when they pass a fragmentation threshold and updates the statistics that have changed. It’s what I use for weekly index and statistics maintenance instead of a maintenance plan. Microsoft’s guide to optimising index maintenance covers the background. Installing Index Optimize This post…

Read More »

Posted in Setup 1 Comment

Create Operator and Standard Alerts

October 31, 2016
| No Comments
| Setup
SQL Server Setup: Create Operator and Standard Alerts

This script will create an operator and standard alerts so SQL Server tells you about serious problems as they happen, rather than when a user does. It creates the DBA_Alerts operator and 13 standard alerts: corruption errors 823, 824 and 825, severity 17 to 25, and database option changes (5084), all emailing the operator. Change…

Read More »

Posted in Setup

Set Up SQL Server Agent Alert Emails (Database Mail)

October 31, 2016
| No Comments
| Setup
SQL Server Setup: Set Up SQL Server Agent Alert Emails (Database Mail)

Tells SQL Server Agent to use Database Mail (profile SQL_Alerting) so it can send alert and job-failure emails. Set up Database Mail first, then run this and restart SQL Server Agent. Windows only; on Linux use mssql-conf. Tested on SQL Server 2017 and 2025 and safe to run more than once. — 06.Setup_SQL_Server_Agent_Alerting_System.sql — Author:…

Read More »

Posted in Setup

Set Up TempDB Data Files: One per CPU, up to 8

October 31, 2016
| No Comments
| Setup
SQL Server Setup: Set Up TempDB Data Files: One per CPU, up to 8

Sets up tempdb: one data file per logical CPU (up to 8), all the same size and growth, plus the log. Missing files are added next to the first data file; existing files are never shrunk. Trace flags 1117 and 1118 are not needed for this on SQL Server 2016 and later. Tested on SQL…

Read More »

Posted in Setup

SQL Server Post-Install Configuration Script

October 31, 2016
| No Comments
| Setup
SQL Server Setup: SQL Server Post-Install Configuration Script

Post-install configuration for a new instance: max server memory and MAXDOP worked out from the server’s memory and CPUs, cost threshold for parallelism, optimize for ad hoc workloads, backup compression and checksum, the DAC, error log count, model growth and Query Store. Run it as it is first: it only shows what it would change….

Read More »

Posted in Setup

Cycle the SQL Server Error Log Nightly (Agent Job)

October 31, 2016
| 1 Comment
| Setup
SQL Server Setup: Cycle the SQL Server Error Log Nightly (Agent Job)

Creates a SQL Agent job, (00:00) Maintenance – CycleErrorLogs, that starts a new error log every night so each log stays small and easy to read. If the job already exists it is left alone. Tested on SQL Server 2017 and 2025 and safe to run more than once. — 02.Cycle_Error_Logs.sql — Author: Clive Roberts…

Read More »

Posted in Setup 1 Comment

Configure msdb Size and Growth in SQL Server

October 31, 2016
| No Comments
| Setup
SQL Server Setup: Configure msdb Size and Growth in SQL Server

Gives msdb a sensible starting size and growth (50 MB, growing 200 MB) so job and backup history do not grow it in tiny steps. It only ever grows a file, never shrinks one. Tested on SQL Server 2017 and 2025 and safe to run more than once. — 01.Configure_MSDB.sql — Author: Clive Roberts DBA….

Read More »

Posted in Setup

Move SQL Server Backup Files with xp_cmdshell

April 11, 2016
| No Comments
| Setup, SQL Server
SQL Server Setup: Move SQL Server Backup Files with xp_cmdshell

declare @cmd nvarchar(200) set @cmd = ‘move \\server\UserDB\*.bak \\server\UserDB\Archive’ exec xp_cmdshell @cmd

Read More »

Posted in Setup, SQL Server

Set Up SQL Server Alerts for Errors 823, 824 and 825

February 5, 2015
| No Comments
| Setup, SQL Server
SQL Server Setup: Set Up SQL Server Alerts for Errors 823, 824 and 825

Errors 823,824, and 825 To do this, run the following command: USE msdb GO EXEC msdb.dbo.sp_add_alert @name = N’823 – Read/Write Failure’, @message_id = 823, @severity = 0, @enabled = 1, @delay_between_responses = 0, @include_event_description_in = 1 GO EXEC msdb.dbo.sp_add_alert @name = N’824 – Page Error’, @message_id = 824, @severity = 0, @enabled = 1,…

Read More »

Posted in Setup, SQL Server

Schedule SQL Server Express Backups with sqlcmd

April 27, 2012
| No Comments
| Setup, SQL Server
SQL Server Setup: Schedule SQL Server Express Backups with sqlcmd

backup.sql BACKUP DATABASE [AdaptiveCR] TO DISK = N’C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Backup\AdaptiveCR.bak’ WITH NOFORMAT, NOINIT, NAME = N’AdaptiveCR-Full Database Backup’, SKIP, NOREWIND, NOUNLOAD, STATS = 10 GO MF20bak.cmd sqlcmd -S .\SQLEXPRESS -i C:\backup.sql Scheduled Tasks to call MF20bak.cmd

Read More »

Posted in Setup, SQL Server

Enable xp_cmdshell in SQL Server (and Turn It Off Again)

October 21, 2011
| No Comments
| Setup, SQL Server
SQL Server Setup: Enable xp_cmdshell in SQL Server (and Turn It Off Again)

EXEC sys.sp_configure N’xp_cmdshell’, 1;

Read More »

Posted in Setup, SQL Server

SQL Server DBA Handbook

Setup, backup and high availability (37)
  • Backing Up and Restoring a Database
  • Restoring a Full Database Backup (SSMS)
  • Restoring a Database to a New Location
  • Backup and Restore with T-SQL
  • Disaster Recovery Planning
  • Basic vs Advanced High Availability
  • Adding a Database to an Availability Group
  • Suspending and Resuming Data Movement
  • Availability Group Health Troubleshooting
  • Quorum Failure
  • Log Shipping
  • Database Mail Setup and Troubleshooting
  • Moving TempDB
  • Database Snapshots
  • Server Build Checklist
  • Encryption
  • TDE: Backing Up the Certificate
  • Data Obfuscation and Masking
  • SQL Server Audit
  • FILESTREAM
  • Orphaned SQL Logins
  • Replicating SQL Server Logins with Their SIDs
  • Login Failures (Error 18456)
  • Random Password Generator
  • Generating the SPNs (Kerberos)
  • SQL Server Replication: Setup, Types and Pitfalls
  • Adding an Article to a Publication
  • Enabling Change Tracking: Good and Bad Points
  • Migrating a Reporting Services Installation (Native Mode)
  • Upgrading SSRS 2005 to 2012 (Quick and Dirty)
  • Azure SQL Options
  • Migrating SQL Server to Azure
  • Building an Availability Group
  • Failover Cluster Instances and Distributed Availability Groups
  • Backup to URL and Backup Encryption
  • PowerShell and dbatools
  • SQL Server Trace Flags
Performance (16)
  • Database Performance Tuning and Index Strategy
  • Data Compression
  • Forwarded Records
  • NUMA
  • Common Memory Issues
  • Average Write Performance
  • Stress Testing the I/O Subsystem with SQLIO
  • When the SQL Server Cache Needs to Be Cleared
  • Parameter Sniffing
  • Table Partitioning
  • Resource Governor
  • What Happens During a Data Change: Buffer Pool, Write-Ahead Log and Durability
  • Measuring Query Performance and Taking a Baseline
  • Reading Execution Plans
  • Plan Caching and Parameterization
  • Statistics Problem or Caching Problem?
Troubleshooting (21)
  • Database Suspect, Recovery Pending or Stuck Recovering
  • Shrinking Databases
  • Transaction Log Full
  • Data File Full and Disk Space (Error 1105)
  • Shrinking Transaction Logs
  • Stopping a Running Job in Job Activity Monitor
  • Failed SQL Agent Job Triage
  • Single-User Mode
  • Tempdb Full or Contention
  • Repairing the WMI Provider (mofcomp)
  • SQL Server Referencing the Wrong Disk Drives
  • Performance Troubleshooting Queries
  • High CPU Troubleshooting
  • SQL Locks
  • SQL Server Error Numbers
  • Monitoring Deadlocks
  • Sleeping Processes
  • DMVs and Session Monitoring
  • Collecting Data with Performance Monitor
  • Collecting a Trace with SQL Profiler
  • Schema Locks and Online Index Maintenance
T-SQL (17)
  • SQL Best Practices
  • T-SQL Coding Conventions and Programming Guidelines
  • Common Table Expressions (CTEs)
  • CROSS APPLY and OUTER APPLY
  • Exporting Data to a File
  • SET IDENTITY_INSERT
  • OPENQUERY with Linked Servers
  • Service Broker in SQL Server
  • Enabling and Resetting Service Broker
  • Change Data Capture (CDC)
  • Extended Events
  • Temporal Tables
  • DDL and DML Audit Triggers
  • Transaction Modes: Autocommit, Explicit and Implicit
  • Error Handling in Transactions: TRY/CATCH, @@TRANCOUNT and XACT_STATE()
  • Read Consistency: Read Committed, RCSI and Snapshot Isolation
  • T-SQL Performance Anti-Patterns

Question of the Day

Setup, backup and high availability (5)
  • Encrypting SQL Server Connections
  • SQL Server Certificate Expiry
  • Moving the SQL Server Error Log
  • Backing Up the Database Master Key
  • Fixed Server Roles in SQL Server
Performance (3)
  • Query Store Capture Mode
  • Rebuilding All Indexes on a Table
  • Disabled Indexes in SQL Server
Troubleshooting (3)
  • Running Scripts with the sqlcmd Utility
  • SQL Server Audit Failures
  • Starting SQL Server with Minimal Configuration
T-SQL (24)
  • Converting Money in T-SQL
  • RANK, DENSE_RANK and ROW_NUMBER
  • Finding Special Characters with PATINDEX
  • COUNT(*) vs COUNT(1) in SQL Server
  • The T-SQL FORMAT Function
  • The Table Value Constructor in SQL Server
  • CREATE PROCEDURE in SQL Server
  • The T-SQL AVG Function
  • @@SERVICENAME and the SQL Server Service Name
  • The SQL Server bit Data Type
  • ALTER SCHEMA TRANSFER
  • The BIT_COUNT Function
  • The STRING_ESCAPE Function
  • The T-SQL BETWEEN Operator
  • The T-SQL SQUARE Function
  • Using a Column Alias in ORDER BY
  • The T-SQL SIGN Function
  • T-SQL Reserved Keywords
  • Adding a Column with a DEFAULT
  • Trailing Spaces in SQL Server
  • SQL Server Regex Functions
  • Aggregates on Empty Sets in T-SQL
  • The SQL Server Vector Data Type
  • The T-SQL CHOOSE Function

All Question of the Day posts (35)

Categories

Sidebar

  • Handbook, news and patches (121)
  • Regain sysadmin access (1)
  • Kill SQL processes (1)
  • Configure MSDB (13)
  • TempDB in use (1)
  • Connected to SQL (1)
  • Move backups (2)
  • VLF details (1)
  • Config Manager error (1)
  • Fill factor (1)
  • Missing indexes (1)
  • Number of cores (1)
  • DBCC CHECKDB (1)
  • Wait times (7)
  • Tail-log backup (1)
  • STUFF function (6)
  • Blocking and deadlocks (2)
  • Locking hints (2)
  • Errors 823, 824, 825 (1)
  • DBCC commands (1)
  • Transaction counts (1)
  • Database details (1)
  • Replication (1)
  • Find jobs (1)
  • Backup progress (1)
  • Pivot table (1)
  • Replication objects (1)
  • Tables with no PK (1)
  • Who dropped the database (1)
  • last_value (1)
  • Parse XML (1)
  • Search a string (1)
  • DATETIME difference (1)
  • Error 3707 (1)
  • SHRINKDATABASE (1)
  • Express backup (1)
  • Enable xp_cmdshell (1)
  • Output a file (1)
  • Start of the month (1)

RSS feed: Clive Roberts Clive Roberts

  • RANK, DENSE_RANK and ROW_NUMBER
    Applies to SQL Server 2019, 2022 and 2025. RANK vs DENSE_RANK is one of those choices that looks cosmetic until a report goes out with the wrong number of rows on it. Both number rows in order and both give tied rows the same number. The difference is what happens to the number after a... […]

Recent Posts

  • Converting Money in T-SQL
  • Maintenance Scripts: Ola Hallengren’s Maintenance Solution 20261129_113033
  • RANK, DENSE_RANK and ROW_NUMBER
  • News: [Video] Office Hours: Reflecting on Microsoft Ignite from Cabo
  • Encrypting SQL Server Connections
  • News: Microsoft’s AI Skills Repo Has a Lot of Potential.
  • Running Scripts with the sqlcmd Utility
  • News: What to Do When the SQL Server Keeps Crashing
  • Finding Special Characters with PATINDEX
  • SQL Server Installs Tested Before and After with dbatools and Pester
  • COUNT(*) vs COUNT(1) in SQL Server
  • The T-SQL FORMAT Function
  • News: SQL Server 2022 SQLskills Blackbelt Credly badge now available
  • The Table Value Constructor in SQL Server
  • CREATE PROCEDURE in SQL Server
  • News: [Video] Office Hours: Back from the PASS Summit
  • The T-SQL AVG Function
  • News: Black Friday Sale – Blackbelt for $399!
  • Capacity Report: When Each Drive Will Be Full
  • SQL Server Security Report: Who Has sysadmin, and What Changed
  • SQL Server Patch Report: Every Instance Against Its Target Build
  • Windows Patch Report: Did This Month’s Updates Land?
  • Integrity Check Report: Proving CHECKDB Actually Ran
  • News: Modernize your apps with Azure SQL Database Hyperscale
  • News: Would Open-Sourcing Microsoft SQL Server Actually Fix Anything?
  • SQL Server Certificate Expiry
  • News: Make Your Nightly ETL Faster with TABLOCKX
  • @@SERVICENAME and the SQL Server Service Name
  • Moving the SQL Server Error Log
  • News: FGCB_ADD_REMOVE Latch Investigation Demo
  • Who Is Really a Sysadmin? Expanding AD Groups in SQL Server with xp_logininfo
  • SSIS Error Report: Finding the Package That Failed
  • Backup Report: Is Every Database Backed Up?
  • Database Inventory Report
  • SQL Server Inventory Report
  • Disk Space Alerts for SQL Server
  • Server Availability Report: Ping and Response Time
  • SQL Server Licensing Report
  • Query Store Capture Mode
  • SQL Server Audit Failures
  • News: [Video] Office Hours in the Backyard
  • The SQL Server bit Data Type
  • News: What Students are Saying About My Latest Classes
  • ALTER SCHEMA TRANSFER
  • News: How to Set Background Images & Movies in SSMS v22
  • Starting SQL Server with Minimal Configuration
  • News: Are Blogs Still Relevant? #tsql2sday
  • Backing Up the Database Master Key
  • News: Free Webcast: My Favorite Query Hints
  • News: Announcing Microsoft Database Hub: An Incredible Pace of Innovation
  • The BIT_COUNT Function
  • Rebuilding All Indexes on a Table
  • The STRING_ESCAPE Function
  • The T-SQL BETWEEN Operator
  • News: [Video] Office Hours: An AI Agent Stops In to Ask a Question
  • The T-SQL SQUARE Function
  • News: The Top 10 SQL Server Wait Types, Worldwide
  • Using a Column Alias in ORDER BY
  • Disabled Indexes in SQL Server
  • News: Who’s Hiring Database People? November 2026 Edition
  • The T-SQL SIGN Function
  • News: My Black Friday Sale on Training Classes is Open Now!
  • T-SQL Reserved Keywords
  • Patch: SQL Server 2022 CU28 (build 16.0.4325.4)
  • Patch: SQL Server 2025 CU11 (build 17.0.5065.9)
  • Patch: SQL Server 2017 CU31 + GDR (build 14.0.3570.2)
  • Patch: SQL Server 2017 GDR (build 14.0.2150.2)
  • Patch: SQL Server 2019 CU32 + GDR (build 15.0.4510.2)
  • Patch: SQL Server 2019 GDR (build 15.0.2210.4)
  • Patch: SQL Server 2022 CU27 + GDR (build 16.0.4315.2)
  • Patch: SQL Server 2022 GDR (build 16.0.1220.3)
  • Patch: SQL Server 2025 CU10 + GDR (build 17.0.5045.3)
  • Patch: SQL Server 2025 GDR (build 17.0.1155.3)
  • Adding a Column with a DEFAULT
  • News: [Video] Office Hours: 4 Great Questions Off Canada
  • Trailing Spaces in SQL Server
  • News: Meet Hugo Kornelis, Execution Plan Expert.
  • SQL Server Regex Functions
  • News: Why You Don’t Get Parallelism When You Ask for The Whole Table
  • Fixed Server Roles in SQL Server
  • News: New Stuff in the Mastering Server Tuning Class
  • Aggregates on Empty Sets in T-SQL
  • News: This Friday’s the Deadline for My Next Live Class Rotation.
  • The SQL Server Vector Data Type
  • The T-SQL CHOOSE Function
  • News: [Video] Talking Pronouns in Alaska
  • News: Why’s This Query So Slow in Prod? Check sp_BlitzPlanCompare.
  • News: AI Stories and Thoughts
  • News: I’m Probably Not Supposed To Show You Microsoft’s Auto-Indexing Tool.
  • SQL Server Trace Flags
  • Statistics Problem or Caching Problem?
  • Plan Caching and Parameterization
  • T-SQL Performance Anti-Patterns
  • Reading Execution Plans
  • Measuring Query Performance and Taking a Baseline
  • News: Thoughts on AI After My Panel Discussion
  • Read Consistency: Read Committed, RCSI and Snapshot Isolation
  • Schema Locks and Online Index Maintenance
  • What Happens During a Data Change: Buffer Pool, Write-Ahead Log and Durability
  • Error Handling in Transactions: TRY/CATCH, @@TRANCOUNT and XACT_STATE()
  • Transaction Modes: Auto commit, Explicit and Implicit
  • PowerShell and dbatools
  • Resource Governor
  • Table Partitioning
  • Backup to URL and Backup Encryption
  • Failover Cluster Instances and Distributed Availability Groups
  • Building an Availability Group
  • Parameter Sniffing
  • DDL and DML Audit Triggers
  • Temporal Tables
  • Extended Events
  • Change Data Capture (CDC)
  • Migrating SQL Server to Azure
  • Azure SQL Options
  • News: [Video] Office Hours on the Last Alaskan Cruise of the Season
  • Upgrading SSRS 2005 to 2012 (Quick and Dirty)
  • Migrating a Reporting Services Installation (Native Mode)
  • Health Check 00: is this SQL Server running well?
  • Health Check 01: server overview
  • Health Check 02: databases
  • Health Check 03: backups
  • Health Check 04: disks and files
  • Health Check 05: SQL Agent jobs
  • Health Check 06: wait statistics
  • Health Check 07: activity and blocking
  • Health Check 08: error log
  • Health Check 09: integrity checks
  • Health Check 10: memory and CPU
  • Health Check 11: tempdb
  • Health Check 12: high availability
  • Performance 01: top queries
  • Performance 02: Query Store regressions
  • Performance 03: missing indexes
  • Performance 04: unused indexes
  • Performance 05: statistics age
  • Performance 06: index fragmentation
  • Performance 07: cardinality estimate skew
  • Performance 08: filtered statistics candidates
  • Performance 09: duplicate and overlapping indexes
  • Performance 10: statistics health
  • Performance 11: cardinality estimator audit
  • Performance 12: implicit conversions
  • Enabling Change Tracking: Good and Bad Points
  • Adding an Article to a Publication
  • SQL Server Replication: Setup, Types and Pitfalls
  • Enabling and Resetting Service Broker
  • Service Broker in SQL Server
  • OPENQUERY with Linked Servers
  • News: Breaking News: Hold Off on SSMS 22.11.0
  • News: Fact-Checking Microsoft’s “PostgreSQL to SQL Field Notes: Connections”
  • SET IDENTITY_INSERT
  • Exporting Data to a File
  • CROSS APPLY and OUTER APPLY
  • Common Table Expressions (CTEs)
  • T-SQL Coding Conventions and Programming Guidelines
  • SQL Best Practices
  • Generating the SPNs (Kerberos)
  • Random Password Generator
  • News: Free Webcast: How to Think Like the SQL Server & Postgres Engines
  • Login Failures (Error 18456)
  • Replicating SQL Server Logins with Their SIDs
  • Orphaned SQL Logins
  • FILESTREAM
  • SQL Server Audit
  • Patch: SQL Server 2017 CU31 + GDR (build 14.0.3560.2)
  • Patch: SQL Server 2017 GDR (build 14.0.2140.2)
  • Patch: SQL Server 2019 CU32 + GDR (build 15.0.4500.2)
  • Patch: SQL Server 2019 GDR (build 15.0.2200.2)
  • Patch: SQL Server 2022 CU27 + GDR (build 16.0.4305.5)
  • Patch: SQL Server 2022 GDR (build 16.0.1210.3)
  • Patch: SQL Server 2025 CU9 + GDR (build 17.0.5015.4)
  • Patch: SQL Server 2025 GDR (build 17.0.1145.4)
  • Data Obfuscation and Masking
  • TDE: Backing Up the Certificate
  • Encryption
  • Collecting a Trace with SQL Profiler
  • Collecting Data with Performance Monitor
  • DMVs and Session Monitoring
  • Sleeping Processes
  • Monitoring Deadlocks
  • SQL Server Error Numbers
  • SQL Locks
  • High CPU Troubleshooting
  • Performance Troubleshooting Queries
  • When the SQL Server Cache Needs to Be Cleared
  • Stress Testing the I/O Subsystem with SQLIO
  • Average Write Performance
  • Common Memory Issues
  • NUMA
  • Forwarded Records
  • Data Compression
  • Database Performance Tuning and Index Strategy
  • Server Build Checklist
  • SQL Server Referencing the Wrong Disk Drives
  • Repairing the WMI Provider (mofcomp)
  • Database Snapshots
  • Tempdb Full or Contention
  • Moving TempDB
  • Single-User Mode
  • Database Mail Setup and Troubleshooting
  • Setup
  • Performance
  • Health Check
  • Troubleshooting
  • T-SQL
  • Patches
  • News
  • Audit
  • Projects

Precious Lite 2025 | All Rights Reserved. Precious Lite theme by Flythemes