Search This Blog

Friday, October 19, 2012

SQL Server DBA - How to uninstall the SQL Server 2008 SP 2


How to uninstall the SQL Server 2008 SP 2?

This Feature is in introduced in SQL Server 2008 SP1 and above.

Before you do the activity, it is recommended to take a full instance backup just in case to recover if anything goes wrong.

Check the Current Service pack level of the SQL Server Instance.






Go to "Programs and Features" options in Control Panel and click on "view installed updates"














Highlight the Service Pack you want to uninstall and click "Uninstall"













The uninstall Service Pack for SQL Server wizard will now come up and click "Next" here once the update rules have been verified.



Select the features for which you need to remove service pack and click "Next"



Once the file check is completed, Click "Next"



Verify the Summary and click "Remove"



Wait for the process to complete


Once this is completed, Restart the computer to finish the SQL Server Setup.



Now verify the changes




Monday, October 15, 2012

SQL Server DBA - T-SQL Queries to find SQL Server Cluster Nodes and Shared Drives


T-SQL Queries to find SQL Server Cluster Nodes and Shared Drives
Find name of the Node on which SQL Server Instance is Currently running

 SELECT SERVERPROPERTY('ComputerNamePhysicalNetBIOS') AS [CurrentNodeName] 


If the server is not cluster, then the above query returns the Host Name of the Server.
Find SQL Server Cluster Nodes
Using Function

SELECT * FROM fn_virtualservernodes() 


Find SQL Server Cluster Shared Drives
Using Function

SELECT * FROM fn_servershareddrives() 

SQL Server DBA - Send e-mail notification when a database is not online


Checking the databases availability is one of the major task of a DBA which has to be performed  at regular intervals to make sure that the critical live databases are always online and fix them immediately if they are not online. This can be done in "n" number of ways and here is one such method.
The method that i am going to discuss below makes use of "Database Mail" option to send e-mails to the intended recipients when the process finds the status of the database which is not online.

After the "Database Mail" Option is configured all you have to do is to create a job with the below code and schedule it to run every five minutes or every one minute depending on the criticality of the databases that you are going to monitor.

Use this Code if you wish to receive the e-mail in HTML format:

if(select count(*) from sys.databases where state_desc<>'Online')>0

Begin

DECLARE @table  NVARCHAR(MAX) ;

SET @table =
    N'<H1>Offline Databases Report</H1>' +
    N'<table border="1">' +
    N'<tr><th>Database Name</th><th>Database Status</th></tr>' +
    CAST ( ( Select td=name, '',td=state_desc from sys.databases where state_desc<>'Online'
              FOR XML PATH('tr'), TYPE
    ) AS NVARCHAR(MAX) )    +
    N'</table>' ;

EXEC msdb.dbo.sp_send_dbmail @profile_name='ProfileName', --Change to your Profile Name
      @recipients='email@domain.com;email1@domain.com', --Put the email address of those who want to receive the e-mail
    @subject = 'Offline Databases Report',
    @body = @table,
    @body_format = 'HTML' ;

END
Else Print 'All Databases are Online'
 
Use this Code if you wish to receive the e-mail in Plain Text format:
 
if(select count(*) from sys.databases where state_desc<>'Online')>0
Begin

EXEC msdb.dbo.sp_send_dbmail @profile_name='ProfileName', --Change to your Profile Name
      @recipients='email@domain.com;email1@domain.com', --Put the email address of those who want to receive the e-mail
    @subject = 'Offline Databases Report',
    @Query='Select rtrim(ltrim(name)) as DatabaseName,rtrim(ltrim(state_desc)) as CurrentDatabaseStatus from sys.databases where state_desc<>''Online'''
    
END
Else Print 'All Databases are Online'