Search code examples
sqldatabasessms-16

Are [ ] needed in a SQL query


SQL Query

I was wondering if the [ ] are needed? and what is the benefit of using them?


Solution

  • 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.