Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Keyboard shortcut to surround a column name with [ and ]

I'm wondering if there's a keyboard shortcut in SSMS to surround a selected column name (or an uninterupted sequence of characters for the given cursor position) with the [ and ] chars.

So if I have user_id and would press something like CTRL + SHIFT + [ + ] it would turn into [user_id]. Is there such a keyboard shortcut?

like image 926
Ben Fransen Avatar asked Mar 25 '15 08:03

Ben Fransen


People also ask

How do you type a column on a keyboard?

Ctrl++ (plus character) is the keyboard shortcut to insert rows or columns. If you are using a laptop keyboard you can press Ctrl+Shift+= (equal sign). Ctrl+- (minus character) is the keyboard shortcut to delete rows or columns.

Can SQL column names have special characters?

SQL Naming and Statement Rules. Was this helpful? The rules for naming database objects (such as tables, columns, views, and database procedures) are as follows: Names can contain only alphanumeric characters and must begin with an alphabetic character or an underscore (_).

Can we use in column name?

Really - just don't do it. Think of this as a formatting thing and do any special naming of columns in your presentation layer. Honestly, anyone who ever has to use your tables in the future will curse you. We usually don't suggest you using special characters in column name.

What are the shortcut keys to group rows so you can expand contract a section of data?

The shortcut key to group rows in Excel is Alt + Shift + Right Arrow. To use this shortcut key, simply select the range of cells that you want to group together and then press Alt + Shift + Right Arrow on your keyboard. Excel will automatically group the data together.


1 Answers

There's no keyboard shortcut out of the box that surrounds text in brackets, but you can you create your own using a custom snippet. You can check out this blog post to get clear steps but I'll list them briefly here.

Open notepad and paste in this xml. Save it as brackets.snippet:

<?xml version="1.0" encoding="utf-8" ?>  
<CodeSnippets  xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">  
<_locDefinition xmlns="urn:locstudio">  
    <_locDefault _loc="locNone" />  
    <_locTag _loc="locData">Title</_locTag>  
    <_locTag _loc="locData">Description</_locTag>  
    <_locTag _loc="locData">Author</_locTag>  
    <_locTag _loc="locData">ToolTip</_locTag>  
   <_locTag _loc="locData">Default</_locTag>  
</_locDefinition>  
<CodeSnippet Format="1.0.0">  
<Header>  
<Title>Brackets</Title>  
                        <Shortcut>br</Shortcut>  
<Description>Snippet for Brackets</Description>  
<Author>SQL Super Hero</Author>  
<SnippetTypes>  
                                <SnippetType>SurroundsWith</SnippetType>  
</SnippetTypes>  
</Header>  
<Snippet>  
<Declarations>  
                                <Literal>  
                                <ID>OpenBracket</ID>  
                                <Default>[</Default>  
                                </Literal>  

                                <Literal>  
                                <ID>CloseBracket</ID>  
                                <Default>]</Default>  
                                </Literal>  
</Declarations>  
<Code Language="SQL"><![CDATA[$OpenBracket$$selected$$CloseBracket$$end$]]>  
</Code>  
</Snippet>  
</CodeSnippet>  
</CodeSnippets>

In SSMS, Go to Tools > Code Snippets Manager.

Click import. Find the Brackets.snippet file and click Open

Choose “My Code Snippets” as the location and click finish

Close and reopen SQL Server Management Studio

You should now be able to use the snippet to surround highlighted text in brackets. The keyboard shortcut to access the snippet is ctrl+k, ctrl+s

The most efficient way to do this is with the following sequence of key presses:

Highlight Desired Text > Ctrl+K,Ctrl+S > M > Enter > Enter > Enter

like image 148
SQLSuperHero Avatar answered Sep 29 '22 17:09

SQLSuperHero