SQL Server Specialist site contains useful information about using and supporting SQL Server as a DBA
View Article  Find servers with fixed Ports on SQL Server

With Central Management Servers  (SQL 2008) you can run this script against all instances in your environment to give you ...   more »

View Article  Script to Run DBCC CheckDB against all databases on an instance.
Script Run DBCC CheckDB against all databases on an instance.   more »
View Article  Maintenance Plan Fails with the following - Failed:(0) Alter failed for Server

Maintenance Plan Fails with the following

 

Databases: All databases

Include indexes

Task start: 2009-06-22T16:57:18.

Task end: 2009-06-22T16:57:19.

Failed:(0) Alter ...   more »

View Article  SQLServerAgent cannot start because the instance of the server (MSSQLSERVER) is not the expected instance
Messages in log:- [sqagtres] OnlineThread: Error 435 bringing resource online. [sqagtres] OnlineThread: ResUtilsStartResourceService failed (status 435) [sqagtres] StartResourceService: Failed to start SQLAgent$Dev_Sleuth service. CurrentState: 1   more »
View Article  Shrinking log issue - Unable to shrink
Cannot shrink log file 4 (*****_Log2) because all logical log files are in use.   more »
View Article  Error Handling in SQL 2005
Templates for handling errors with Try Catch:-   more »
View Article  Monitor for long running agent jobs
Schedule this job to look for long running agent jobs, alter variables as required   more »
View Article  House Keeping - Delete old files using SSIS

First add the variables

 

 

 

The folders are strings and the number of days to keep the ...   more »

View Article  Server Info
Generates information abour SQL Server and the version installed   more »
View Article  File Locations
Gives the location of the database files works with SQL Server 2000 and 2005   more »
View Article  List Databases on Server
Lists the databases available on a server   more »
View Article  Database Properties
Script to list database properties for use on SQL Server 2000 and 2005 servers.   more »
View Article  SQL Server 2005 DDL Triggers
See article http://www.simple-talk.com/sql/sql-server-2005/sql-server-2005-ddl-TRIGGER-workbench/ which describes 
SQL Server 2005 DDL Triggers.
I have implemented these with some amendments:- 


CREATE TABLE [dbo].[DDLChangeLog]...   more »
View Article  SQL Agent Error

Have you ever seen the following error in the SQL Server Agent error log:-

Message
[425] delay_between_response attribute (10 sec) ...   more »
View Article  Restore the Master Database
On SQL Server 2000 to restore the Master database, copy the instal disk to the server being restored and alter ...   more »
View Article  Script to add alerts and notifications to DBA User - SQL 2005
This script adds an operator 'DBA' and reports all job failures and alerts to this Operator. Database Mail or SQL Mail needs to be enabled.   more »
View Article  MOM reporting backp failure, when backups succesful

Today the MOM agent reported backup failure on one of my servers:-

 

Description:

BACKUP failed to complete the command ...   more »

View Article  Alter the collation to database default

/*---------------------------------------------------------------------------------------------------

Purpose: This script generate scripts to alter the collation

Author: Carolyn Richardson

Date: 05/10/2007

---------------------------------------------------------------------------------------------------*/

USE{databasename}

GO...   more »

View Article  Identify tables on Server with collation issue
This script will identify tables on all databases on a server that have differing collations, collation differences have probably occured between upgrades to SQL Server versions or where the server default differs   more »
View Article  Find tables with large logical fragmentation
--Quick script to find tables with large logical fragmentation and generate a script to alter the fill factor

CREATE TABLE...   more »

View Article  Upgrading to SQL Server 2005
Upgrading to SQL Server 2005   more »
View Article  How to transfer logins and passwords between instances of SQL Server
How to transfer logins and passwords between instances of SQL Server    more »
View Article  Alerts for SQL Server 2000

-- These are our preferred Alerts for SQL Server 2000/2005

-- Author: SQL Server Specialists (www.SQLServerSpecialists.co.uk)

USE MSDB

GO

IF(EXISTS(SELECT name FROM msdb.dbo.sysalerts WHERE name= N'Demo: Sev. 19 Errors'))

---- Delete the alert with the same name. EXECUTE msdb.dbo.sp_delete_alert @name = N'Demo: Sev. 19 Errors'

IF(EXISTS(SELECT name FROM msdb.dbo.sysalerts WHERE name= N'Demo: Sev. 20 Errors'))

---- Delete the alert with the same name. EXECUTE msdb.dbo.sp_delete_alert @name = N'Demo: Sev. 20 Errors'

IF(EXISTS(SELECT name FROM msdb.dbo.sysalerts WHERE name = N'Demo: Sev. 21 Errors'))

---- Delete the alert with the same name. EXECUTE msdb.dbo.sp_delete_alert @name = N'Demo: Sev. 21 Errors'

IF(EXISTS(SELECT name FROM msdb.dbo.sysalerts WHERE name= N'Demo: Sev. 22 Errors'))

---- Delete the alert with the same name. EXECUTE msdb.dbo.sp_delete_alert @name = N'Demo: Sev. 22 Errors'

IF(EXISTS(SELECT name FROM msdb.dbo.sysalerts WHERE name= N'Demo: Sev. 23 Errors'))

---- Delete the alert with the same name. EXECUTE msdb.dbo.sp_delete_alert @name = N'Demo: Sev. 23 Errors'

IF(EXISTS(SELECT name FROM msdb.dbo.sysalerts WHERE name= N'Demo: Sev. 24 Errors'))

---- Delete the alert with the same name. EXECUTE msdb.dbo.sp_delete_alert @name = N'Demo: Sev. 24 Errors'

IF(EXISTS(SELECT name FROM msdb.dbo.sysalerts WHERE name= N'Demo: Sev. 25 Errors'))

---- Delete the alert with the same name. EXECUTE msdb.dbo.sp_delete_alert @name = N'Demo: Sev. 25 Errors'

IF(EXISTS(SELECT name FROM msdb.dbo.sysalerts WHERE name= N'Demo: Full msdb log'))

---- Delete the alert with the same name. EXECUTE msdb.dbo.sp_delete_alert @name = N'Demo: Full msdb log'

IF(EXISTS(SELECT name FROM msdb.dbo.sysalerts WHERE name = N'Demo: Full tempdb'))

---- Delete the alert with the same name. EXECUTE msdb.dbo.sp_delete_alert @name = N'Demo: Full tempdb'

 

IF(EXISTS(SELECT name FROM msdb.dbo.sysalerts WHERE name= N'Backup Failure'))

---- Delete the alert with the same name. EXECUTE msdb.dbo.sp_delete_alert @name = N'Backup Failure'

BEGIN

EXECUTE msdb.dbo.sp_add_alert @name = N'Backup Failure', @message_id = 3201, @severity = 0, @enabled = 1, @delay_between_responses = 60, @include_event_description_in = 5, @category_name = N'[Uncategorized]'

END

/*Start of Alert*/

IF(EXISTS(SELECT name FROM msdb.dbo.sysalerts WHERE name = N'Deadlock Event'))

---- Delete the alert with the same name. EXECUTE msdb.dbo.sp_delete_alert @name = N'Deadlock Event'

BEGIN

EXECUTE msdb.dbo.sp_add_alert @name = N'Deadlock Event', @message_id = 1205, @severity = 0, @enabled = 1, @delay_between_responses = 60, @include_event_description_in = 5, @category_name = N'[Uncategorized]'

END

/*Start of Alert*/

IF(EXISTS(SELECT name FROM msdb.dbo.sysalerts WHERE name= N'Driver or Hardware problem with the I/O system'))

---- Delete the alert with the same name. EXECUTE msdb.dbo.sp_delete_alert @name = N'Driver or Hardware problem with the I/O system'

BEGIN

EXECUTE msdb.dbo.sp_add_alert @name = N'Driver or Hardware problem with the I/O system', @message_id = 845, @severity = 0, @enabled = 1, @delay_between_responses = 60, @include_event_description_in = 5, @category_name = N'[Uncategorized]'

END

/*Start of Alert*/

IF(EXISTS(SELECT name FROM msdb.dbo.sysalerts WHERE name= N'Fatal Error in current Proccess - 020'))

---- Delete the alert with the same name. EXECUTE msdb.dbo.sp_delete_alert @name = N'Fatal Error in current Proccess - 020'

BEGIN

EXECUTE msdb.dbo.sp_add_alert @name = N'Fatal Error in current Proccess - 020', @message_id = 0, @severity = 20, @enabled = 1, @delay_between_responses = 10, @include_event_description_in = 5, @category_name = N'[Uncategorized]'

END

/*Start of Alert*/

IF(EXISTS(SELECT name FROM msdb.dbo.sysalerts WHERE name = N'Fatal Error in Database Processes - 021'))

---- Delete the alert with the same name. EXECUTE msdb.dbo.sp_delete_alert @name = N'Fatal Error in Database Processes - 021'

BEGIN

EXECUTE msdb.dbo.sp_add_alert @name = N'Fatal Error in Database Processes - 021', @message_id = 0, @severity = 21, @enabled = 1, @delay_between_responses = 10, @include_event_description_in = 5, @category_name = N'[Uncategorized]'

END

/*Start of Alert*/

IF(EXISTS(SELECT name FROM msdb.dbo.sysalerts WHERE name = N'Fatal Error In Resource - 019'))

---- Delete the alert with the same name. EXECUTE msdb.dbo.sp_delete_alert @name = N'Fatal Error In Resource - 019'

BEGIN

EXECUTE msdb.dbo.sp_add_alert @name = N'Fatal Error In Resource - 019', @message_id = 0, @severity = 19, @enabled = 1, @delay_between_responses = 10, @include_event_description_in = 5, @category_name = N'[Uncategorized]'

END

/*Start of Alert*/

IF(EXISTS(SELECT name FROM msdb.dbo.sysalerts WHERE name= N'Fatal Error: Database Integrity Suspect - 023'))

---- Delete the alert with the same name. EXECUTE msdb.dbo.sp_delete_alert @name = N'Fatal Error: Database Integrity Suspect - 023'

BEGIN

EXECUTE msdb.dbo.sp_add_alert @name = N'Fatal Error: Database Integrity Suspect - 023', @message_id = 0, @severity = 23, @enabled = 1, @delay_between_responses = 10, @include_event_description_in = 5, @category_name = N'[Uncategorized]'

END

/*Start of Alert*/

IF(EXISTS(SELECT name FROM msdb.dbo.sysalerts WHERE name = N'Fatal Error: Hardware Error - 024'))

---- Delete the alert with the same name. EXECUTE msdb.dbo.sp_delete_alert @name = N'Fatal Error: Hardware Error - 024'

BEGIN

EXECUTE msdb.dbo.sp_add_alert @name = N'Fatal Error: Hardware Error - 024', @message_id = 0, @severity = 24, @enabled = 1, @delay_between_responses = 10, @include_event_description_in = 5, @category_name = N'[Uncategorized]'

END

/*Start of Alert*/

IF(EXISTS(SELECT name FROM msdb.dbo.sysalerts WHERE name= N'Fatal Error: Table Integrity Suspect - 022'))

---- Delete the alert with the same name. EXECUTE msdb.dbo.sp_delete_alert @name = N'Fatal Error: Table Integrity Suspect - 022'

BEGIN

EXECUTE msdb.dbo.sp_add_alert @name = N'Fatal Error: Table Integrity Suspect - 022', @message_id = 0, @severity = 22, @enabled = 1, @delay_between_responses = 10, @include_event_description_in = 5, @category_name = N'[Uncategorized]'

END

/*Start of Alert*/

IF(EXISTS(SELECT name FROM msdb.dbo.sysalerts WHERE name= N'Fatal Errror - 025'))

---- Delete the alert with the same name. EXECUTE msdb.dbo.sp_delete_alert @name = N'Fatal Errror - 025'

BEGIN

EXECUTE msdb.dbo.sp_add_alert @name = N'Fatal Errror - 025', @message_id = 0, @severity = 25, @enabled = 1, @delay_between_responses = 10, @include_event_description_in = 5, @category_name = N'[Uncategorized]'

END

/*Start of Alert*/

IF(EXISTS(SELECT name FROM msdb.dbo.sysalerts WHERE name= N'Full Log - 9002'))

---- Delete the alert with the same name. EXECUTE msdb.dbo.sp_delete_alert @name = N'Full Log - 9002'

BEGIN

EXECUTE msdb.dbo.sp_add_alert @name = N'Full Log - 9002', @message_id = 9002, @severity = 0, @enabled = 1, @delay_between_responses = 60, @include_event_description_in = 5, @category_name = N'[Uncategorized]'

END

/*Start of Alert*/

IF(EXISTS(SELECT name FROM msdb.dbo.sysalerts WHERE name= N'Full msdb log - 9002'))

---- Delete the alert with the same name. EXECUTE msdb.dbo.sp_delete_alert @name = N'Full msdb log - 9002'

BEGIN

EXECUTE msdb.dbo.sp_add_alert @name = N'Full msdb log - 9002', @message_id = 9002, @severity = 0, @enabled = 1, @delay_between_responses = 10, @include_event_description_in = 5, @database_name = N'msdb', @category_name = N'[Uncategorized]'

END

/*Start of Alert*/

IF(EXISTS(SELECT name FROM msdb.dbo.sysalerts WHERE name= N'Full tempdb - 9002'))

---- Delete the alert with the same name. EXECUTE msdb.dbo.sp_delete_alert @name = N'Full tempdb - 9002'

BEGIN

EXECUTE msdb.dbo.sp_add_alert @name = N'Full tempdb - 9002', @message_id = 9002, @severity = 0, @enabled = 1, @delay_between_responses = 10, @include_event_description_in = 5, @database_name = N'tempdb', @category_name = N'[Uncategorized]'

END

/*Start of Alert*/

IF(EXISTS(SELECT name FROM msdb.dbo.sysalerts WHERE name= N'Lock Allocation'))

---- Delete the alert with the same name. EXECUTE msdb.dbo.sp_delete_alert @name = N'Lock Allocation'

BEGIN

EXECUTE msdb.dbo.sp_add_alert @name = N'Lock Allocation', @message_id = 17125, @severity = 0, @enabled = 1, @delay_between_responses = 60, @include_event_description_in = 5, @category_name = N'[Uncategorized]'

END

/*Start of Alert*/

IF(EXISTS(SELECT name FROM msdb.dbo.sysalerts WHERE name = N'Lock request timeout period exceeded'))

---- Delete the alert with the same name. EXECUTE msdb.dbo.sp_delete_alert @name = N'Lock request timeout period exceeded'

BEGIN

EXECUTE msdb.dbo.sp_add_alert @name = N'Lock request timeout period exceeded', @message_id = 1222, @severity = 0, @enabled = 1, @delay_between_responses = 60, @include_event_description_in = 5, @category_name = N'[Uncategorized]'

END

/*Start of Alert*/

IF(EXISTS(SELECT name FROM msdb.dbo.sysalerts WHERE name= N'Misc Table Error'))

---- Delete the alert with the same name. EXECUTE msdb.dbo.sp_delete_alert @name = N'Misc Table Error'

BEGIN

EXECUTE msdb.dbo.sp_add_alert @name = N'Misc Table Error', @message_id = 2511, @severity = 0, @enabled = 1, @delay_between_responses = 60, @include_event_description_in = 5, @category_name = N'[Uncategorized]'

END

/*Start of Alert*/

IF(EXISTS(SELECT name FROM msdb.dbo.sysalerts WHERE name = N'Non Logged SQL Server Shutdown'))

---- Delete the alert with the same name. EXECUTE msdb.dbo.sp_delete_alert @name = N'Non Logged SQL Server Shutdown'

BEGIN

EXECUTE msdb.dbo.sp_add_alert @name = N'Non Logged SQL Server Shutdown', @message_id = 20531, @severity = 0, @enabled = 1, @delay_between_responses = 60, @include_event_description_in = 5, @category_name = N'[Uncategorized]'

END

/*Start of Alert*/

IF (EXISTS(SELECT name FROM msdb.dbo.sysalerts WHERE name= N'Potentially Fatal Error Insufficient Resources'))

---- Delete the alert with the same name. EXECUTE msdb.dbo.sp_delete_alert @name = N'Potentially Fatal Error Insufficient Resources'

BEGIN

EXECUTE msdb.dbo.sp_add_alert @name = N'Potentially Fatal Error Insufficient Resources', @message_id = 0, @severity = 17, @enabled = 1, @delay_between_responses = 60, @include_event_description_in = 4, @category_name = N'[Uncategorized]'

END

/*Start of Alert*/

IF(EXISTS(SELECT name FROM msdb.dbo.sysalerts WHERE name = N'Unexpected failure acquiring application lock.'))

---- Delete the alert with the same name. EXECUTE msdb.dbo.sp_delete_alert @name = N'Unexpected failure acquiring application lock.'

BEGIN

EXECUTE msdb.dbo.sp_add_alert @name = N'Unexpected failure acquiring application lock.', @message_id = 21414, @severity = 0, @enabled = 1, @delay_between_responses = 60, @include_event_description_in = 5, @category_name = N'[Uncategorized]'

END

/*Start of Alert*/

IF(EXISTS(SELECT name FROM msdb.dbo.sysalerts WHERE name= N'Unexpected failure releasing application lock'))

---- Delete the alert with the same name. EXECUTE msdb.dbo.sp_delete_alert @name = N'Unexpected failure releasing application lock'

BEGIN

EXECUTE msdb.dbo.sp_add_alert @name = N'Unexpected failure releasing application lock', @message_id = 21415, @severity = 0, @enabled = 1, @delay_between_responses = 60, @include_event_description_in = 5, @category_name = N'[Uncategorized]'

END

 

 

View Article  Save DTS packages as Structured Storage Files

CREATEPROCEDURE dbo.usp_SaveDTS

@DTSname varchar(256)='',

@Applicationpath varchar(700)='',

@destinationpath varchar(700)='\\Serverpath\Software\SQL 2000\DTS\',

@switches varchar(200)=' -E -!X '

AS

/*=============================================================================================================================

Stored Proc: usp_SaveDTS

Purpose: Saves DTS Packages as Structured Storage File

Author: Carolyn Richardson

Date: 25/09/2007

NOTES: Alter the @destinationpath to point to the correct UNC path to directory

=============================================================================================================================*/

SET  quoted_identifier off

SET nocount on

SET concat_null_yields_null off

DECLARE @Count int

,@folderexist int ,@maxcount int ,@query varchar(1000) ,@date varchar(10) ,@versionid varchar(40) ,@createdate varchar(25)

SET @date =convert(varchar(10),getdate(),112)

SET @Count =1

PRINT  'Saving DTS packages - Started'

PRINT getdate()

SET  @Applicationpath = @Applicationpath +'DTSRUN.exe'

CREATE TABLE  #DTSTABLE

(id intidentity(1,1), DTSname varchar(256),versionid varchar(40), createdate varchar(25))

IF @dtsname =''

BEGIN

INSERT INTO  #DTSTABLE

(dtsname,versionid,createdate)

SELECT name,versionid,replace(replace(convert(varchar(25),createdate,109),':',' '),' ','_')

FROM msdb..sysdtspackages

END

ELSE

BEGIN

INSERTINTO  #DTSTABLE

(dtsname,versionid,createdate)

SELECT name,versionid,replace(replace(convert(varchar (25),createdate,109),':',' '),' ','_')

FROM msdb..sysdtspackages

WHERE name= @DTSname

END

IF(SELECTcount(*)FROM #dTStable)= 0

BEGIN

SET  @date =convert(varchar(100),getdate(),109)

PRINT  'Error: No valid DTS package found for saving'

END

ELSE

BEGIN

-- Check folder for Server Exists

SET  @destinationpath = @destinationpath +@@Servername CREATETABLE #Files (Files int, Folder int, parent int) INSERT  #Files EXEC master.dbo.xp_fileexist @destinationpath

SELECT @folderexist = Folder FROM #Files

IF @folderexist <>1 BEGIN
SET @query ='MKDIR "'+@destinationpath+'"'

PRINT @query EXEC master..xp_cmdshell @query SET @destinationpath = @destinationpath
END ELSE BEGIN
PRINT  'Information:'+ @destinationpath +' already exist. Skipping Folder Creation'

END BEGIN DELETE FROM #Files --Check folder for save date exists SET  @destinationpath = @destinationpath +'\'+@date INSERT  #Files EXEC master.dbo.xp_fileexist @destinationpath SELECT  @folderexist = Folder FROM #Files IF  @folderexist <>1 BEGIN
SET @query ='MKDIR "'+@destinationpath+'"'

PRINT @query EXEC master..xp_cmdshell @query SET @destinationpath = @destinationpath
END ELSE BEGIN
PRINT  'Information:'+ @destinationpath +' already exist. Skipping Folder Creation'

END END SET @maxcount =(SELECTMAX(id)FROM #dTStable)

WHILE @Count <= @maxcount

BEGIN
SELECT @dtsname = dtsname,@versionid=versionid ,@createdate =createdate

FROM #DTSTABLE WHERE id = @Count SET @query =''+@applicationpath +''+' -S"'+@@servername+'" -N"'+@dtsname+'" -V"'+@versionid +'" -F"'+@destinationpath++'\'+@dtsname+'_'+@createdate+'.dts"'+ @switches SET @query = "EXEC master..xp_cmdshell '" + @query + "'"

PRINT @query

EXEC(@query)

IF @@error<> 0

BEGIN

PRINT 'Error'

END

SET @Count = @Count+1

END

END

PRINT getdate()

PRINT 'Save DTS packages - Completed'

DROP TABLE #DTSTABLE

DROP TABLE #Files

GO

SET QUOTED_IDENTIFIER OFF

GO

SET ANSI_NULLS ON

GO

View Article  Add database Mail to SQL Server 2005
Setting up Database Mail - SQL Server 2005   more »