In SQL Server one way we optimize code is by adding indexes. Indexes help queries by essentially letting the engine know 鈥渉ey, here鈥檚 the fast way to get directly to the data you want鈥. The alternative is doing full table scans to read all the data, which sucks.
When reviewing code in SQL Server Management Studio (SSMS) we have a similar built-in tool to help save you time: Bookmarks! Bookmarks aren鈥檛 quite like indexes but they do help you mark locations in code that you can quickly jump聽to. This is especially helpful when reviewing code in large scripts.
For this example I鈥檓 going to use the amazingly useful聽 (which you should be using if you鈥檙e not already) from Glenn Berry ( | ). This script is jam packed with all sorts of amazingly insightful information on your server and databases. However I often need to jump around to different parts of the script.
For example, when performance tuning I like to run Glenn鈥檚 code for getting back the top wait types on the server. After that I jump down to the section on top cached queries/procedures to get a sense of what鈥檚 happening. If I do this manually there鈥檚 about 300 lines of code separating the two sections. That鈥檚 a lot of annoying scrolling!
Instead what you can do is create bookmarks at these locations. You can do this one of two ways. First set your cursor at the desired location in code. You can set bookmarks by going to the Edit menu聽鈥>Bookmarks->Toggle Bookmark. The other way is when you have your cursor set you can use the keyboard shortcut of Ctrl+K, Ctrl+K to add a bookmark. When you鈥檝e created a bookmark you鈥檒l see a small grey/white box in the left side window. Now scroll to other locations in code you鈥檇 like a bookmark and repeat this process.

To navigate between Bookmarks you can use the keyboard shortcut Ctrl+K, Ctrl+N to go to next one or Ctrl+K, Ctrl+P to navigate to previous. Now you can quickly and easily jump between sections of code! Happy coding.

Cross posted at my new MSDN blog:聽
2 replies on “Using Bookmarks in SQL Server Management Studio”
Nice! Thank you for sharing this. Bookmarked.
Thanks, glad you found it useful!