• Categories

  • Recent Posts

  • Archives

  • Copyright Notice

    Copyright © Nancy Hidy Wilson, 2010-2013. Unauthorized use and/or duplication of this material without express and written permission from this blog’s author and/or owner is strictly prohibited. Excerpts and links may be used, provided that full and clear credit is given to Nancy Hidy Wilson and nancyhidywilson.wordpress.com with appropriate and specific direction to the original content.

TSQL2sday #024 – Prox ‘n’ Funx

What is TSQL2sday? Two years ago, Adam Machanic (blog | twitter) had this brilliant idea for a monthly SQL Server blogger event (the origin of TSQL2sday).  This month’s event is hosted by Brad Schulz (blog) and the selected topic is “Prox ‘n’ Funx” (aka Procedures and Functions).

Today, I’m sharing my favorite SQL Server metadata function – SERVERPROPERTY(‘propertyname’).  This handy function has been around since at least SQL Server 2000. If you need to get a quick “report” of the high level configuration information about your SQL Server instance – this is the function to use. Of course, with each new version of SQL Server it is subject to change, so always check usage in BOL (this link is to SQL 2008 R2 Books Online, but you can get to other versions from there).

If a property isn’t valid for a particular version of SQL Server (or if you just flat out typo the property name!), then NULL will be returned. Here’s a sample query for you to try out.  

And if you need database property info – guess what?  There are DATABASEPROPERTY and DATABASEPROPERTYEX functions you should check out! Until next time – happy TSQL2sday!


		
Advertisements

TSQL2sday #20 – T-SQL Best Practices

What is TSQL2sday? Back in late 2009, Adam Machanic (blog | twitter) had this brilliant idea for a monthly SQL Server blogger event (the origin of TSQL2sday) on a unified topic.  This month’s event is hosted by Amit Banerjee (blog | twitter) and the selected topic is “T-SQL Best Practices”.

This will be short and to the point.  My #1 “best practice” tip when writing any code is to include comments! Whether a SELECT statement from a single table or a complex multi-table join using CROSS APPLY, please write a comment stating the objective of the command. You’ll be surprised how soon you forget why you wrote the command in the first place and why you wrote it the way you did.

I’ll open up the proverbial can of worms, though by stating my preferences for when to use block comments /* */ versus dash comments –.

I prefer to use the block method for actual comments.

/* Uncomment the code below in order to list all databases */

I prefer to use the dash comments to comment out actual T-SQL code.

–Select name from sys.databases

What’s your preference for T-SQL comment indicators?