SQL SERVER – CTRL+SHIFT+] Shortcut to Select Code Between Two Parenthesis

Every weekend brings creative ideas and accidents brings best unknown secrets in front of us. Just a day while working with complex SQL Server code in SSMS I came across very interesting shortcut which I have never used before and instantly fell in love with it. It is totally possible that you are familiar with this but for me it was the first time and I was surprised that I did know know this short cut so far.

Shortcut key is CTRL+SHIFT+]. This key can be very useful when dealing with multiple subqueries, CTE or query with multiple parentheses. When exercised this shortcut key it selects T-SQL code between two parentheses.

Let us see the examples to understand the same. In each of the examples I have put the cursor at the position displayed and pressed CTRL+SHIFT+] and it has selected the code between two corresponding parentheses.

Cursor position 1

SQL select query window in visual studio.

Cursor position 2

Visual query designer.

Cursor position 3

SQL Server query with FROM clause.

If you are a developer and have to code with complex queries, you will totally appreciate that this feature can save so much of the time for development. I often remember my experience as a developer when I have lost a lot of hours to just balance parentheses. As I said yesterday I found this shortcut accidently. How many of you were aware of this feature? Is there any other useful feature you would like to share with us? Please leave a comment and if I have not covered it earlier, I will share it due credit on this blog.

Published by Pinal Dave on SQLAuthority. More of my work at pinaldave.com.

SQL Server, SQL Server Management Studio, SQL Shortcut
Previous Post
SQL SERVER – Retrieve SQL Server Installation Date Time
Next Post
SQLAuthority News – 2 Whitepapers Announced – AlwaysOn Architecture Guide: Building a High Availability and Disaster Recovery Solution

Related Posts

25 Comments. Leave new

  • Ayman El-Ghazali
    July 7, 2012 8:10 am

    Thank you! Very simple but extremely useful. I always end up moving the cursor with the arrow keys since it usually matches the with the corresponding parenthesis. It doesn’t always work to well. I will give this a shot on Monday. Enjoy your weekend.

    Reply
  • Vinay B Hiraskar
    July 7, 2012 10:27 am

    Nice One!! I use to use this shortcut in Visual Studio, But I was not aware that it’s also in MS SQL.
    Thanks Pinal Sir, I learnt Nice tip this Weekend :)

    Reply
  • SHUBHAM SAXENA
    July 7, 2012 2:13 pm

    Thanks Pinal Sir,
    Its very useful.I use arrow key to find subquery starting braces and ending braces.

    Reply
  • firas abuzaina
    July 7, 2012 7:07 pm

    you can use it with begin and end

    Reply
  • we can also use CTRL+] to move between parenthesis or a begin-end pair.

    Reply
    • :) So easy, so nice!
      Maybe someone knows some shortcut for code formatting.
      Eg.: I`ve got query which is written in 1 line, without tabs, spaces…
      And I would like to format it (many lines,select section,from and where in another lines…)
      DO you know anything useful for it?

      Reply
      • There is no shortcut to format code up to SQL Server 2008 as per my knowledge but you can try Redgate SQL Prompt which is really a very good tool. There is also available another free online tool for it at

        I hope these can be helpful.

      • Thanks,
        however Redgate SQL Prompt is a very good tool, it`s not free and trial period is only few weeks so I was starting to use this tool: and I`ve got very good first opinion. Actually it did everything what I wanted to do :-)

  • Nice tip! Thanks!

    Reply
  • cool info..thanks .. :-)

    Reply
  • Yet again providing an extremely useful tip. Thank you.

    Reply
  • I cant get this to work in my SSMS 2012 or 2008 R2

    Reply
  • Fermín Bernaus (@fbernaus)
    July 12, 2012 2:13 pm

    No equivalent in SQL Server 2008 R2, look for “Move the cursor to the next brace, extending the selection”:

    Reply
  • Nice tips; Thanks

    Reply
  • flightglobal
    July 17, 2012 3:48 pm

    Awesome

    Reply
  • You are a GURU my friend!

    Reply
  • This just doesn’t work on ssms 2012. I badly want to use it as I am struggling with a hell lot of brackets.

    Reply
  • Hi Pinaldave
    I’ using SQL Server 2014 and this trick isn’t working for. CAn you please help me out? I have a lot of subquries and I wanna detect which Parenthesis belong together.

    Mike

    Reply
  • @mikybrain maybe you have to use CTRL + SHIFT + ] instead of CTRL + SHIFT + J ?
    (i did this error ‘:) )

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *

Fill out this field
Fill out this field
Please enter a valid email address.