1

Why all variables and datatypes are kept in '[]'

CREATE TABLE [dbo].[tblExerciseMultiMailTypeStructureDetails](
[ExerciseMultiMailID] [int] NOT NULL
5
  • Which dbms are you using? (Perhaps MS SQL Server?) Commented Apr 29, 2019 at 8:35
  • 1
    That is invalid standard SQL - looks like Microsoft SQL Server or MS Access. Commented Apr 29, 2019 at 8:36
  • The square brackets are usually there to qualify object names since you could have spaces in a table or column name. Commented Apr 29, 2019 at 8:37
  • They don't have to be kept in the brackets, but it's often done in MS Access or t-sql code. Firstly it allows you to specify names that have spaces in them, which otherwise would create a syntax error (normally a space would denote the end of the name, but if you use brackets then this role is taken by the bracket instead). Secondly some people might find it helps readability of the code because you can see the names very distinctly from keywords and other items Commented Apr 29, 2019 at 8:40
  • Because your column name can be sql keyword. so all variables and datatypes are different. Commented Apr 29, 2019 at 8:42

1 Answer 1

2

Any name that are same as SQL Server Keywords or containing embaded space must be enclosed in double quotes("") or square brackets([]). Which words are considered as keyword varies,depending on the compatibility level to which you have set your database.

Sign up to request clarification or add additional context in comments.

1 Comment

Good answer. For the sake of consistency (and for better search results), I personally always use delimiters for any names/identifiers in my SQL statements. Except for table aliases (for which I use non-keyword mnemonics) and for (built-in) data types. I once had an issue with MS Access using a column name that was a reserved keyword. Since then I delimit columns and tables by default.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.