Thank you John McCormack for hosting this month of T-SQL Tuesday.
For the past couple of years as a DBA, I migrated several databases and used many handy scripts that helped me made my work easier. These scripts may be simple but if you have a migration project involving several SQL Servers with some hundreds of databases, test and production database migrations becomes tedious. I would like to share some of then here which you might already known them very well.
- I used this script answered by AlexK (look for the script with most accepted answer) to kill all connections to a database. I used this script in Development/Test/QA/Production during database migrations. A very handy script. I used this script while migrating 200 servers from SQL Server 2000 to SQL Server 2016.
- Other Script that I have used for migrations are sp_help_revlogin to transfer the logins during migrations.
- When using transactional replication between the servers, I used to see several distribution job failures when a new snapshot generated or during the subscriber reinitialization. The snapshot generating the .sch files for replication with ANSI_PADDING turned OFF instead of ON. I found a very handy PowerShell script answered by Asaf Mohammad in Microsoft forum which will search the .sch file having SET ANSI_PADDING OFF in all the folders and subfolders of the snapshot and replace them with SET ANSI_PADDING ON. Thanks to Asaf for saving many hours. As per the recommendation from this forum, I used this script as a second step in my snapshot agent job so this setting is fixed within the snapshot agent job. After using this PowerShell script, my distribution job worked fine.
None of the scripts I mentioned above were written by me. It is the hard work of other professionals who created these scripts and freely shared the scripts to the world helping other professionals. Kudos to all of them. There are several other scripts that I use on regular basis but I wanted to keep this post short and only mention the ones which I used frequently since past couple of years.
I am looking forward to see what other SQL family members post about their favorite handy scripts!