THE SQL Server Blog Spot on the Web

Welcome to SQLblog.com - The SQL Server blog spot on the web Sign in | |
in Search

Jamie Thomson

This is the blog of Jamie Thomson, a data mangler in London working for Dunnhumby

Code Navigation (10 days of SSDT – Day 10)

SQL Server Data Tools (SSDT) was released in Spring 2012 and I have been using it to build SQL Server databases nearly every day since then. In that time I’ve learnt a lot about how to make best use of the tool and I want to share that experience in a new series of blog posts called “10 days of SSDT”. I shall be publishing a different blog post every day for 10 days, each day revealing something that you may not know about SSDT. I hope you enjoy the series and contribute via the comments!

One of the aspects of T-SQL development that really grates on me is that the features of both the language and tooling are light years behind that of our brethren that write in “higher order” languages like C#, VB, Java etc… One of the tooling features that folks who live in Visual Studio take for granted is code navigation, happily that feature is now available in Visual Studio for T-SQL developers when one installs SSDT.

Be aware that SSDT’s code navigation features only work when you are working offline using SSDT projects.

There are only two keyboard shortcuts you need to learn to master code navigation (and please do use keyboard shortcuts, don’t wimp out and use the mouse):

  • F12
  • Shift+F12

Go To Definition

Go To Definition allows you to position your cursor inside a reference to an object, press F12, and SSDT will show you the definition of that object. Sounds simple, and it is, but its wonderfully useful when you get into the swing of using it. The following screenshots are an attempt to convey it.

Notice here the cursor is positioned inside a reference to a table called [datawarehouse].[DimCurrency]:

SNAGHTML1325ff31

Simply pressing F12 at that point opens the definition of that table:

SNAGHTML1327b945

Find All References

Find All References does the opposite of Go To Definition, it shows everywhere that an object is referenced. If you’ve ever been afraid to remove an object from a database because you didn’t know what was using it (let’s face it, we’ve all been there) then this feature can be a lifesaver.

Take the previous example of table [datawarehouse].[DimCurrency]. If I again position the cursor inside a reference to that object and this time press Shift+F12 SSDT will search through my database model and present a list of all the objects where it is referred to:

SNAGHTML13318b6e

In the screenshot immediately above we see that this table is referred to 51 times. Those references may be in stored procedures, views, functions, triggers, constraints or extended properties. Double-clicking on any of the entries in that list takes you directly to the definition of the referring object.

Summary

That really is it. Two very simple features but ones which can have a massively positive effect on your productivity.

Hopefully this goes without saying but code navigation does not work if you are referencing objects using dynamic SQL, this is because SSDT sees that dynamic SQL string as just that, a string, rather than a reference to another object in the model. Probably just bear that in mind.

Code navigation is top of the list of features that drive my preference for developing in offline SSDT rather than online in SSMS.

@Jamiet 

If you want to learn more about SSDT then come along to my training course Introduction to SQL Server Data Tools in association with Technitrain on 23rd/24th February 2015 in London. There is a discount if you register before the end of 2014.

Earlier posts in this series:

Published Monday, October 13, 2014 8:57 AM by jamiet

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Comments

 

Tom H said:

Thanks for this series.  

I've been using database projects for a while now and can't imaging building my databases any other way.  I haven't really had the chance to dig too much into some of the nuances and features so articles like this are really helpful,

Again, thanks and I hope you can do the other 20 days someday.

October 14, 2014 2:04 PM
 

Hennie de Nooijer said:

Good stuff..

December 2, 2015 3:44 AM

Leave a Comment

(required) 
(required) 
Submit

This Blog

Syndication

Privacy Statement