Blog Archives

Tips ‘N’ Tricks – TFS – Always Check-Out the Latest Version of Code from TFS

I had previously written a tip on Right way to get the latest code from TFS. Well, that’s when you want to get the latest for viewing/reviewing purposes etc. However, when multiple developers are working on the same set of files, it is important that all the dependencies are taken care properly and before making any changes on the server, it is essential that we get a latest version of code from TFS to our local workspace, Check-Out the code and then we can make changes and Check-In the code.
Now, you might ask, why should I always manually Get the Latest Version of code and then Check-Out? When we are saying that it is best practice and in fact a mandatory step especially when working in a team, shouldn’t there be an option which by default checks out the latest version of code? Yes you are right! There indeed is an option in Visual Studio/Team Foundation Server to do that. Simply follow the below steps to know how to go about doing it.
  • Open Visual Studio 2010
  • Connect to your Team Project on Team Foundation Server
  • Go to Tools | Options…
  • Go to Source Control in the left navigation pane and expand it
  • From the expanded menu, select Visual Studio Team Foundation Server
  • Now select the check box Get latest version of item on check out as shown below
  • Click on OK and you are done

Get Latest Version of item on check out

Now, you don’t need to manually get the latest version of code from Team Foundation Server into your Local Workspace before Checking-Out. The above option will take care of Getting the Latest Version before performing the Check-Out. All you need to do is, just go and Check-Out the code which you need and rest will be taken care by the above setting.

Similar settings can be made at the Team Project level so that it is set as a default option for all the users connecting to the Team Project. For more information, visit this msdn article.
Note: This demonstration is based on Visual Studio 2010 Team Foundation Server (TFS)

Tips ‘N’ Tricks – SSMS – Generate Script for Multiple Select Objects in One-Go

Generating scripts of various objects in SQL Server Management Studio (SSMS) is a common requirement and generating the script for all the objects is a pretty straight forward task, which can be done using a simple approach as detailed out this msdn article. However, let us say that you want to generate the create scripts for a selected set of tables in your database (say AdventureWorksDW database). How would you do it? Well, keep reading to know how 🙂

  • Open SSMS, Connect to the SQL Server Instance
  • Go to Object Explorer, and expand Databases folder
  • Expand the data Database from which you want to script objects
  • Select the Tables folder
  • Go to View | Object Explorer Details (alternatively you can press F7). Now the Object Explorer Details looks as shown below.

Object Explorer with List of Tables in SSMS

  • Now, to generate Create Table Script for multiple selected objects in AdventureWorksDW database, select multiple tables in the Object Explorer Details (by holding Ctrl key).
  • Right click and select Script Table as | CREATE TO | New Query Editor Window as shown below.

Generate Script for Multiple Objects in One Shot in SSMS

This will generate the CRATE TABLE Script for all the objects selected in the Object Explorer Details window.

What approach do you use to perform this task?

Note: Above demonstration is based on SQL Server 2008 R2 Management Studio.

Take a look at the other Tips and Tricks in this Series on Tips, Tricks, Techniques, and Shortcuts to Improve Productivity, and Design and Coding Skills.

Tips ‘N’ Tricks – SSMS – Quickest way to SELECT and Query All Columns from a Table in SQL Server

Most of you, who are working on T-SQL must be knowing that using “SELECT * FROM <<Table>>” syntax is treated as a Bad Practice and instead, using “SELECT <<Column Names>> FROM <<Table>>” syntax is recommended as a Best Practice for various reasons (discussing those is not in scope of this article).

So, to be able to follow the Best Practice, it requires typing in the names of individual columns which is a time-consuming process especially if there are huge number of columns to be specified in the Select List. To overcome this very concern, there is actually a really cool shortcut for specifying the names of the columns in the SELECT statement with just few mouse clicks. Here is how this simple trick works.

I had previously published a tip titled Quickest way to SELECT All Columns from a Table at Just Learned on It became very popular and I received a great feedback from the community members. In the interest of my blog’s subscribers and visitors, I am going to present that tip here with a couple of visuals as follows.

Say you want to select all the columns from a table, for which you would write a query something like this:


FROM dbo.DimProduct

Now, as specified above, we need to replace the asterisk (*) in the above query with the list of all the columns present in DimProduct table. To do this, follow these steps:

  • Go to SSMS, Open a new query window, Type SELECT followed by a space on First Line and FROM dbo.DimProduct on the Second Line.
  • Go to Object Explorer | Database Containing DimProduct Table | DimProduct Table
  • Expand the DimProduct table and click on Columns folder
  • Hold the Left Mouse Button and Drag the Columns folder on to the Query Window after SELECT, which will pull all the columns from DimProduct table and place them after the SELECT statement in the query window separated by commas (,) as shown below.

Drag the Columns Folder to Right of SELECT Clause

When you drag the Columns folder, All the Columns from DimProduct are placed after the SELECT Clause and before the FROM Clause in the above query window as shown below.

Comma Seperated Columns Inserted between SELECT and FROM Clause

Now, you can make slight formatting changes to suit your needs and if you want, you can even remove some of the columns based on your need (Remember that, removal is always easier than addition when it comes to Coding and hence this approach!).

This is one of my all time favorite tips and I use this almost all the times 🙂

Do let me know, what is your approach of Selecting Columns from a SQL Server Table in a T-SQL Query by leaving a comment below.

Take a look at the other Tips and Tricks in this Series on Tips, Tricks, Techniques, and Shortcuts to Improve Productivity, and Design and Coding Skills.