0

Do we add '[]' just to differentiate the system defined keyword from our own ... ? Or is there any other reason behind using '[]'? Thanks!

dev27
  • 605
  • 1
  • 7
  • 15
  • The use of square brackets in t-sql is to allow you to use reserved words as object names or aliases. However, I would recommend not using reserved words to begin with. – Zohar Peled May 30 '15 at 20:16
  • Have a read of this [`Database Identifider`](https://msdn.microsoft.com/en-us/library/ms175874.aspx) – M.Ali May 30 '15 at 20:18

2 Answers2

0

The use of square brackets in t-sql is to allow you to use reserved words as object names or aliases.
However, I would recommend not using reserved words to begin with.
Here is my prefered method of avoiding the use of reserved words.

Community
  • 1
  • 1
Zohar Peled
  • 79,642
  • 10
  • 69
  • 121
  • I guess we cannot avoid using [] if in our object relational model the table column is mapped to a property which is a reserved keyword in sql. – dev27 May 30 '15 at 20:35
  • I am not an ORM expert, but I do believe you should be able to map a property to a column with a different name in most ORMs. Otherwise you would not need mappings at all... – Zohar Peled May 30 '15 at 20:51
0

say you want to name your table my table only way to do this is to put it like so: [my table] . Same principle applies for other database objects.

create table [my table] (
column1 varchar(30), column2 varchar(50))
Java Main
  • 1,521
  • 14
  • 18