I was wondering if the [ ] are needed? and what is the benefit of using them?
Asked
Active
Viewed 56 times
0
-
Tag with the database you are using. – Gordon Linoff Apr 13 '18 at 02:03
-
3Possible duplicate of [What is the use of the square brackets \[\] in sql statements?](https://stackoverflow.com/questions/52898/what-is-the-use-of-the-square-brackets-in-sql-statements) – Daniele Cappuccio Apr 13 '18 at 02:04
-
I would use `\`table name\`` instead for escaping when you have white spaces in your names. – StackSlave Apr 13 '18 at 02:06
1 Answers
1
Square braces are never needed in a standard SQL query, because they are not part of the standard.
Some databases (notably SQL Server and related dialects) use square braces as escape characters for identifiers. Identifiers that contain only letters, digits, and underscore (for the most part) and that are not reserved words do not need to be escaped. I strongly advise that all your identifiers follow these rules.
In your sample query, the identifiers are all fine. They do not need to be escaped. The square braces are just visual clutter.

Gordon Linoff
- 1,242,037
- 58
- 646
- 786
-
2@Origin27 I would say that it's generally bad practice to use them, because using them allows you to use bad names for your databases, tables, and columns. – Tim Biegeleisen Apr 13 '18 at 02:16
-
-
@Origin27 . . . I agree with Tim. Further, they make queries harder to write and to read. – Gordon Linoff Apr 13 '18 at 02:22