Skip to main content

Posts

Notes on changing SQL Server's Collation

The  SQL_Latin1_General_CP1_CI_AS collation is a legacy collation and we are recommended by Microsoft to use the supported  Latin1_General_CI_AS .  So when I was installing a cluster recently to host the databases for SCOM 2012 I chose the latter. This was a mistake as unfortunately it still requires the old collation .  How to change a SQL Server's collation after you've installed it is well documented  and so is the command, but there are a couple of gotchas that might be worth remembering. The command executed from a cmd.exe window is: z:\Setup /QUIET /ACTION=REBUILDDATABASE /INSTANCENAME=MSSQLSERVER /SQLSYSADMINACCOUNTS=domain\AUser /SAPWD=MyPassword /SQLCOLLATION=SQL_Latin1_General_CP1_CI_AS Probably due to the /QUIET option virtually no progress or errors are returned - you just need to wait for five minutes looking at an empty DOS box while it does its thing. The user account name and SA password should not be in quotes or square...

The Purge SQL Agent Job for MDW takes a long time to complete

I use the dbWarden alerts to inform me if a SQL job is taking longer to complete than normal and I got one this morning:   Click to enlarge I noticed by looking at the history this purge job was gradually taking longer and longer to complete each day since I installed it again ( see mylast post on this ): RunDate RunTime Duration ExecutionStatus JobName 04/10/2013 02:00:01 00:00:45 Succeded mdw_purge_data_[MDW] 05/10/2013 02:00:00 00:13:27 Succeded mdw_purge_data_[MDW] 06/10/2013 02:00:00 00:17:03 Succeded mdw_purge_data_[MDW] 07/10/2013 02:00:01 00:30:58 Succeded mdw_purge_data_[MDW] 08/10/2013 02:00:01 01:04:25 Succeded mdw_purge_data_[MDW] 09/10/2013 02:00:01 01:41:39 Succeded mdw_purge_data_[MDW] 10/10/2013 02:00:01 02:35:17 Succeded md...

Fun and games with the Management Data Warehouse (MDW and Data Collectors)

The SQL Server Management Data Warehouse (when you first come across it) seems to promise so much if the verbiage from Microsoft and some other websites is to to believed. But when you install it you may find that it is not as useful as it could be. This is a shame but we are currently only on v2 of the product with SQL 2012 so one hopes it will improve in subsequent versions. However, it probably is worth playing with if you have never used it before - at least you can show your boss some reports on general server health when he asks for it and you have nothing else in place. There is one big problem with it though if you decide that you don't want to use it any more, uninstalling it is not supported! Mad, I know. But as usual some very helpful people in the community have worked out, what seems to me, a pretty safe way of doing it. I had a problem with my MDW. The data collector jobs were causing a lot of deadlocking on some production servers and impacting performance. I...

Generate scripts to attach multiple databases

There is a handy little "by product", if you like, when running queries which means you can quickly generate scripts to do different things. Below is an example of generating multiple "attach" commands that you can copy from the results pane into the main SSMS window for execution. I have found this very handy in the past: SELECT 'CREATE DATABASE [' + name + '] ON ( FILENAME = N''F:\MSSQL\Data\' + name + '.mdf'' ), ( FILENAME = N''E:\MSSQL\Log\' + name + '_log.ldf'' )  FOR ATTACH GO ' FROM master . dbo . sysdatabases WHERE name not in ( 'master' , 'msdb' , 'model' , 'tempdb' ) ORDER BY name

Display all the DBCC commands and their syntax

There are a large number of DBCC commands and it's easy to forget their names and syntax/order of parameters. To help you can run the commands below: -- Show list of all DBCC commands DBCC TRACEON ( 2520 ) DBCC HELP ( '?' ) GO -- Show help for specific command DBCC HELP ( show_statistics ) This piece of code is ideal for a  Snippet .

How to generate scripts to alter location of all databases

This is is a handy piece of TSQL code which generates a list of TSQL commands that can be used to alter the location of all user databases to the path specified. It assumes that the filenames for the data file and log file will match the database name plus ".mdf" for the former and "_log.ldf" for the latter. This can be executed while the SQL service is running and will only take effect after it has been restarted. You will of course have to physically copy the files to the new location when the service is down. USE master ; GO SELECT 'ALTER DATABASE [' + name + '] MODIFY FILE ( NAME = [' +  name + '], FILENAME = ''F:\MSSQL\Data\' + name + '.mdf'' ); ALTER DATABASE [' + name + '] MODIFY FILE ( NAME = [' + name + '_Log], FILENAME = ''E:\MSSQL\Log\' + name + '_Log.ldf'' ); GO ' FROM sysdatabases WHERE [sid] <> 0x01 ...