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
Cursor position 2
Cursor position 3
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.
Reference: Pinal Dave (https://blog.sqlauthority.com)
25 Comments. Leave new
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.
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 :)
Thanks Pinal Sir,
Its very useful.I use arrow key to find subquery starting braces and ending braces.
you can use it with begin and end
we can also use CTRL+] to move between parenthesis or a begin-end pair.
:) 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?
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.
Good answer Suvendu!
Thanks Pinal Sir
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!
cool info..thanks .. :-)
Yet again providing an extremely useful tip. Thank you.
I cant get this to work in my SSMS 2012 or 2008 R2
I got it working. I wasn’t on a 2008 DB. Needs to be SQL 2008 R2 DB.
No equivalent in SQL Server 2008 R2, look for “Move the cursor to the next brace, extending the selection”:
I got it to work on SQL Server 2008 R2 (10.50.2500) DB and SSMS 2008 R2.
Nice tips; Thanks
Awesome
You are a GURU my friend!
This just doesn’t work on ssms 2012. I badly want to use it as I am struggling with a hell lot of brackets.
You need to enable the Intellisense to get this working
I am not able to enable Intellisense. Is it because I am connecting to 2005 SQL?
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
@mikybrain maybe you have to use CTRL + SHIFT + ] instead of CTRL + SHIFT + J ?
(i did this error ‘:) )