question

binoj avatar image
binoj asked

disable square braces when generating scripts from SSMS

How do I disable square braces when generating scripts from SSMS?

sql-serverssmsscriptautomation
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Steve Jones - Editor avatar image
Steve Jones - Editor answered

While it might bother you, it's a good practice. It ensures that any strange characters in your objects, spaces, etc., don't cause issues when you run the script. You might think you'll never do this, but with a version upgrade, that table you created in a previous version might now have a keyword for a name.

10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Matt Whitfield avatar image
Matt Whitfield answered

You can't, as far as I know.

10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Kev Riley avatar image
Kev Riley answered

Currently there is no option to do this. It is SQL Servers fail-safe way of generating scripts for YOUR objects, that you might have named with a reserved keyword.

10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Phil Factor avatar image
Phil Factor answered

I think it is a nuisance, and I agree wholehartedly with the questioner that there ought to be a way to kick it out. Although I have to admit that I occasionally use them when I accidentally use a reserved word, I don't see why one should not be able to enforce a 'standards' mode in a database, and do without the square braces. To illustrate the way that one can abuse all guidelines for sensible programming by means of square braces, see my blog post. Evil Code

1 comment
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Valentino Vranken avatar image Valentino Vranken commented ·
Prefer not to use them either, so annoying. Have a look at the following feature request, I added a comment to broaden its context a little: https://connect.microsoft.com/SQLServer/feedback/details/540306/ssms-improvements-required-for-dragging-columns-from-object-explorer
0 Likes 0 ·
dvroman avatar image
dvroman answered

Hate It. I believe there should be something like the VB "Option Explicit" which would explicitly disable any reserved words from being a DB object.

10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Darren 1 avatar image
Darren 1 answered

RegEx Find and Replace. Find "[\[\]]" Replace ""

2 comments
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Matt Whitfield avatar image Matt Whitfield ♦♦ commented ·
That's a bit of a sub-standard approach, as it would blanket remove all square braces, even where they are required for non-natural identifiers.
0 Likes 0 ·
TimothyAWiseman avatar image TimothyAWiseman commented ·
@Matt, I agree with you, but if the original poster want to disable them then the poster presumably knows that they are not necessary. This is the closest thing to a direct solution to the original question I saw.
0 Likes 0 ·
kferrell avatar image
kferrell answered
Been using SQL Server since Sybase 4.2 and this drives me NUTS! It is NOT good practice to use brackets. What is good practice is NOT USING RESERVED WORDS as object names. Bracketing object names is a quick way to violate all sorts of bad practices, like using punctuation in your name. The genesis of brackets had to do with cross platform development and conversions. You can always add brackets to your code if you need to and SQL is smart enough to know the difference contextually 95% of the time anyway. When scripting, SSMS should identify reserved words that are being used as objects and bracket ONLY those. This would make it more obvious that you are using a reserved word. Please change this.
1 comment
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

msacar avatar image msacar commented ·

@kferrell It really sucks that when I right-click and choose "Select top 1000 rows" option, it brings a new tab with the SELECT statement with square brackets and all, but leave the selected database as "master". So when I go ahead and write another query on the same tab I HAVE TO a) explicitly specify the db name or b) choose my database from the dropdown menu. Same for "Edit Query Text" option under Activity Monitor. Like come on SSMS, you know which db was it run under, so auto select the db for that query when you open it.

Maybe off-topic but I think these can be grouped under "annoying issues of SSMS".

0 Likes 0 ·
Jon Crawford avatar image
Jon Crawford answered

Our IT use multiple instances on the same server, so server\SQL1, etc. If I don't use square brackets, then everything fails. User-schema objects (Domain\LoginID) also fail. Square brackets don't interfere with anything when your objects are well-formed names, despite Phil's gnarly examples, I think it's a very low-risk thing to use and solves more problems than it creates.

10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.