SSMS Tools Custom Script For Index Information

Posted by Josh | Posted in SQL Server | Posted on 14-01-2011

Tags: , , ,

2

The other day I was having a chat with a developer around our SQL coding standards, specifically the naming conventions. He made an interesting point: the name shouldn’t matter, because it’s the metadata ( what table its on, the index key columns, included columns, etc) that matters. My response was that while that’s true, it’s helpful as a production DBA to have the name, which is readily available via a few clicks in SSMS, be a meaningful one that gives you some inkling of what the index is. This is especially true at 3AM when you’re troubleshooting issues. His response: write a script that you can run to give the information and use that instead of the GUI.

And while I’m not switching my position on naming standards (Have you seen SSMS’s default naming for indexes? Ugh…), I’m up for any challenge, so write a script I did. I actually use this with SSMS Tool‘s “Custom Script” functionality so when I right-click a table, it is easily run.

SELECT 'Index Information'
SELECT	i.name [Index Name],
		i.type_desc [Index Type],
		CASE i.is_primary_key
			WHEN 1 THEN 'Yes'
			ELSE 'No'
		END [Is Primary Key],
		(
			SELECT	c2.name + ', '
			FROM	sys.index_columns ikc
						JOIN sys.columns c2
							ON ikc.column_id = c2.column_id
							AND ikc.object_id = c2.object_id
							AND ikc.is_included_column = 0
			WHERE	ikc.index_id = i.index_id
					AND ikc.object_id = i.object_id
			ORDER BY ikc.index_column_id ASC
			FOR XML PATH('')
		) [Index Columns],
		(
			SELECT	c1.name + ', '
			FROM	sys.index_columns ikc
						JOIN sys.columns c1
							ON ikc.column_id = c1.column_id
							AND ikc.object_id = c1.object_id
							AND ikc.is_included_column = 1
			WHERE	ikc.index_id = i.index_id
			ORDER BY ikc.index_column_id ASC
			FOR XML PATH('')
		) [Included Columns]

FROM	sys.indexes i
			JOIN sys.objects o
				ON i.object_id = o.object_id
			JOIN sys.schemas s
				ON o.schema_id = s.schema_id
WHERE	o.name = '|ObjectName|'
		AND s.name = '|SchemaName|'

It returns some basic metadata about the index definition, such as the name, type, and columns (both included and key). I’ll be trying this out and undoubtedly adding more columns in the coming weeks, but wanted to share it.

What useful SSMS ToolPack custom scripts do you have?

Choose your weapon: picking a tool for GTD

Posted by Josh | Posted in GTD | Posted on 15-12-2008

Tags: , ,

4

In Which Our Hero Selects His Weapon In The Battle Against Chaos

In many ways, the principles of GTD are rather tool-agnostic.  You can write down your tasks and dump your memory into any one of many different repositories, both physical and electronic.  That being said, it is helpful to have some kind of framework available with which you can evaluate all the various options out there.

In my experience, a GTD system works best when it meets the following criteria:

The system is readily available to you at all times

Your chosen repository will do you little good if you are not able to easily refer to it at all times. Whose to say, for instance, that you won’t suddenly get inspiration on a new project while out running (it happened to me today, as a matter of fact)?

Ease of use

Similar to the above, but not necessarily the same. You could probably find a Web 2.0 app that was available on both your iPhone and online (therefore meeting the above criteria), but was still an absolute boor to use. If it’s not easy to query, edit, and analyze what’s in your system, you will surely shy away from using it, rendering it worthless.

Tagging or other means of categorizing items

Without the ability to easily filter and sort your lists based on contexts or other tags, the task of deciding what to do at any given moment becomes harder. For instance, if you are on the train headed home after work, and you only have access to your phone (and no internet), you should be able to quickly see a list of all the tasks in the “@phone” context.  It also makes it very easy to check off your “next action” and “waiting for” items across multiple projects.

Tracking of completed items

It is an accepted fact in the world of psychology that positive reinforcement is very powerful in changing behavior patterns. As you continue in your efforts to ingrain the principles of GTD into your daily life, being able to see all that you’ve accomplished can be a very powerful motivator to continue down your chosen path. I’ve found it amazingly satisfying to look back at the past week on a Friday and see just how much I’ve been able to do.


I believe all three of these could be accomplished with any number of tools, be it a web app like Remember The Milk (a subtle endorsement for my weapon of choice) or a simple paper based notebook. To me, that’s the point of the framework: it’s platform independent. Hopefully you will find it useful in your quest to find the right tools for implementing GTD.

Speaking of which, if you already have a framework, what is it? How do you evaluate all the various options available to us?