Sparx Systems Forum
Enterprise Architect => General Board => Topic started by: SystemsTinkerer on February 08, 2022, 08:23:32 am
-
Hello EA users,
I am trying to understand how the square brackets have been using in the following bit of SQL code:
( t_object o
left join t_diagramobjects dob on dob.[Object_ID] = o.[Object_ID])
code is part of the Orphan search of elements by Geert:
https://bellekens.com/2015/10/16/searching-for-real-orphans-in-enterprise-architect/
What does the square bracket mean? Why is it used here?
Any tips or references to consult would be useful - thank you!
BR,
Oz
-
It's the syntax for M$Access (see the Mikeysoft docs). You need it only for keywords (if you know what a keyword is) and could be left away for the above. Suspicious column names would be Note(s), Value and the like. It doesn't hurt to overdo with brackets except for human readability.
q.
-
Hi q,
Thank you for the pointer! I will look up MS Access related SQL but upon searching, I haven't come across any similar type of example where a sq brackets are used.
Just referring to the same code, would the following code work just as well, without the sq brackets?:
dob.Object_ID = o.Object_ID
-
Yes, this syntax is used in SQL Server as well.
You'll need that to tell the engine you are talking about a database/table/column in case these collide with some kind of keyword or something.
If that is not the case you can use them or not, doesn't matter. Some tools add those brackets automatically as part of their autocomplete feature when writing SQL
Say you have a table called "transaction", you'll get an error if you do "select * from transaction", but it will work just fine if you do "select * from [transaction]"
Some other vendors use other means to indicate that, such as backticks (MySQL) and the like.
I'm not sure if this syntax is Microsoft specific, or included in the ANSI SQL
Geert
-
Hi Geert,
Thank you for clarifying the issue with the sq brackets - really appreciate it :)
Best,
Oz
-
I guess it does not matter whether ANSI or Mickeysoft. One can just say that you need to be aware of different flavors. Like dialects in a language. You can understand most of it all around. But some lingo is only understood in certain areas. It's not just escaping of keywords but different syntax too.
q.
-
Hi q,
Thank you for your take on this.
Yes, I looked it up and saw for instance the keyword or SQL syntax "select" was used with a table called select, I would need to use: select * from [select]
Cheers!