Automatic matching of syntax pairs is a feature of SQL Server Management Studio which gives you immediate feedback on whether syntax elements that must be coded in pairs are correctly paired when you write any query in query editor. It is also known as delimiter matching.
Whenever, you cursor in one of the delimiter in a pair, you can use keyboard shortcut CTRL+] to jump to the matching delimiter. Using this you can quickly identify any missing pair of delimiter.
When you go over the delimiter and the one that you have selected it’s pair turn gray, in this way query editor lets you visually identify code blocks and check for mismatched pairs of delimiter. If you do not find any matching pair of any delimiter that means something wrong.
Automatic delimiter matching identifies the following sets of delimiters:
Lead Delimiter Closing Delimiter
BEGIN TRY END TRY
BEGIN CATCH END CATCH
Lets see it in action, Go to SQL Server Management Studio, open a query editor window.
Now write some piece of code that uses some parentheses as shown below.
SELECT Number FROM ( SELECT 1 AS Number UNION SELECT 2 AS Number UNION SELECT 3 AS Number ) TBL
Sometime it’s hard to see the parentheses, when you have a large piece of T-SQL code as gray color is very light and less visible on white query editor screen.
In this case, If you want to change the gray color to something else. Then you can change the color from Tools menu in SQL Server Management.
Go to Tools then Select Options..
Next you will see, a options dialog box opens.
Now under the Environment, click on Fonts and Colors, then select Brace Matching (Rectangle).
You will see that the default color is gray for Item background.
Now you can select any color for Item Background.
Lets change the color to Yellow, and click on OK button.
After clicking on OK button, Lets go back to query editor.
Now, just go over the first opening braces “(“, you will see that the matching pairs (including opening and closing) turn in Yellow.
You will see, that the yellow color is more highlighted in comparison to gray.
Lets take one more example using TRY.. CATCH block.
For a BEGIN CATCH.. END CATCH pair when you type a BEGIN CATCH first followed by END CATCH, you will see a highlighting turns on when you type the last letter that is “H” in END CATCH.
You will notice that yellow color is more highlights than gray color.
BEGIN TRY SELECT Number FROM ( SELECT 1 AS Number UNION SELECT 2 AS Number UNION SELECT 3 AS Number ) TBL END TRY BEGIN CATCH SELECT 'Error' END CATCH
73 total views, 1 views today