Search

Monday, June 30, 2014

Unable to remove SQL Server 2008 after removing from cluster

I was unable to uninstall SQL Server after it was removed from Failover Cluster Manager. It was logging below error in application log:

Product: Microsoft SQL Server 2008 Database Engine Services — Error 25012. There was an error attempting to remove the configuration of the product which prevents any other action from occuring. The current configuration of the product is being cancelled as a result.

I had followed below steps to uninstall SQL Server:

1. Open Registry Editor (Start -> run -> type regedit)

2. Navigate to the following key:
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SQL Server\MSSQL10.MSSQLSERVER\ClusterState\SQL_Engine_Core_Inst

3. Change the value of this “SQL_Engine_Core_Inst” key from 1 to 0.

4. Uninstall as normal through Programs and Features

Monday, June 23, 2014

Finding a Table in all databases on Server

dbo.sp_MSforeachdb procedure will execute the attached string as a command against every database on the server. Any question mark(?) , within the string will be replaced by every database name.
We can use the Information_Schema view Tables to see the tables list in the current DB:

Select * From DB1.Information_Schema.Tables

So by combining both SP and View we can search for a Table in all databases in Server

EXEC dbo.sp_MSforeachdb 'SELECT ''?'', * FROM [?].INFORMATION_SCHEMA.TABLES WHERE Table_Name LIKE ''Items'' '

Monday, June 2, 2014

Find Table with Max. rows & Size

You can use the below query to get all tables with No of rows and size. User required View Database State permission on the Server to use below DMV

SELECT SN.Name AS [Schema Name], ST.Name AS [Table Name], SI.Name AS [Index Name], PS.Reserved_Page_Count * 8 AS [Total Space Consumed (in KB)], PS.Used_Page_Count * 8 AS [Used Space (in KB)], (PS.Reserved_Page_Count - PS.Used_Page_Count) * 8 AS [Free Space (in KC)], CASE WHEN PS.Index_ID IN (0, 1) THEN PS.Row_Count ELSE NULL END AS [Row Count]
FROM SYS.DM_DB_PARTITION_STATS AS PS INNER JOIN SYS.OBJECTS AS ST ON ST.OBJECT_ID = PS.OBJECT_ID INNER JOIN SYS.SCHEMAS AS SN ON SN.SCHEMA_ID = ST.SCHEMA_ID LEFT JOIN SYS.INDEXES AS SI ON SI.OBJECT_ID = PS.OBJECT_ID AND SI.INDEX_ID = PS.INDEX_ID
WHERE ST.IS_MS_SHIPPED = 0
ORDER BY [Total Space Consumed (in KB)] DESC