SQL Server

Source of info: http://www.mattbutton.com/2011/06/01/sql-profiler-templates-missing/ Upon trying to create a trace template in SQL Server Profiler, I was able to name the trace but there were no events to choose from in the “Events Selection” tab, even when the “Show All Events” box was checked.  If I clicked the “Column Filters” button...

More
  • 2016-03-19

This is the basic query text to use whenever you need to loop through a result set in SQL Server using TSQL. In this example we are getting every database name and printing it out. /* Declare variable that will hold a single result */ DECLARE @DBName varchar(50) /* Declare...

More
  • 2016-03-19

Do transactions apply in dynamic SQL, in SQL Server? In a word, yes. For proof, run the following chunks of code: No Transactions You can see the third row having a value of “5”, showing that it was updated CREATE TABLE #T( ID INT IDENTITY(1,1) ,COL1 VARCHAR(100) ,COL2 VARCHAR(100) );...

More
  • 2016-03-19

Source: http://sqlserverplanet.com/dmvs/missing-indexes-dmv SELECT mid.statement ,migs.avg_total_user_cost * (migs.avg_user_impact / 100.0) * (migs.user_seeks + migs.user_scans) AS improvement_measure ,OBJECT_NAME(mid.Object_id) ,’CREATE INDEX [idx_’ + LEFT(PARSENAME(mid.statement, 1), 32) + ‘_’ + CONVERT(VARCHAR, mig.index_group_handle) + ‘_’ + CONVERT(VARCHAR, mid.index_handle) + ‘]’ + ‘ ON ‘ + mid.statement + ‘ (‘ + ISNULL(mid.equality_columns, ”) + CASE WHEN...

More
  • 2016-03-18

—- Allow advanced options to be changed. –EXEC sp_configure ‘show advanced options’, 1 –GO —- Update the cuently configured value for advanced options. –RECONFIGURE –GO —- Enable xp_cmdshell –EXEC sp_configure ‘xp_cmdshell’, 1 –GO —- Update the cuently configured value for xp_cmdshell –RECONFIGURE –GO —- Disallow further advanced options to be...

More
  • 2016-03-18

cls import-module failoverclusters Import-Module -Name SQLPS -DisableNameChecking $servers = “comma”,”separated”,”server”,”list” foreach($server in $servers) { try { $virtual_name = $server; $instances = ”; try{ $virtual_name = ((get-clusterresource -Cluster $server -ErrorAction SilentlyContinue -WarningAction SilentlyContinue | get-clusterparameter VirtualServerName -ErrorAction SilentlyContinue -WarningAction SilentlyContinue | Select Value -ErrorAction SilentlyContinue -WarningAction SilentlyContinue)[0].Value ) } catch{} $server...

More
  • 2016-03-18