Book a Demo

Author Topic: EA SQL search using [] brackets?  (Read 3818 times)

SystemsTinkerer

  • EA User
  • **
  • Posts: 48
  • Karma: +0/-0
    • View Profile
EA SQL search using [] brackets?
« 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

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +397/-301
  • I'm no guru at all
    • View Profile
Re: EA SQL search using [] brackets?
« Reply #1 on: February 08, 2022, 10:07:44 am »
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.

SystemsTinkerer

  • EA User
  • **
  • Posts: 48
  • Karma: +0/-0
    • View Profile
Re: EA SQL search using [] brackets?
« Reply #2 on: February 09, 2022, 05:19:46 am »
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

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13505
  • Karma: +572/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: EA SQL search using [] brackets?
« Reply #3 on: February 09, 2022, 05:32:55 am »
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

SystemsTinkerer

  • EA User
  • **
  • Posts: 48
  • Karma: +0/-0
    • View Profile
Re: EA SQL search using [] brackets?
« Reply #4 on: February 09, 2022, 07:12:30 am »
Hi Geert,

Thank you for clarifying the issue with the sq brackets - really appreciate it  :)

Best,
Oz

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +397/-301
  • I'm no guru at all
    • View Profile
Re: EA SQL search using [] brackets?
« Reply #5 on: February 09, 2022, 10:00:11 am »
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.

SystemsTinkerer

  • EA User
  • **
  • Posts: 48
  • Karma: +0/-0
    • View Profile
Re: EA SQL search using [] brackets?
« Reply #6 on: February 09, 2022, 06:02:40 pm »
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!