Use explicite JOIN's rather then implicite

plsql
tsql

(Christian Rohr ) #1

A good rule suggestion:

  • description of the Rule answering to the question “why?” : what’s the impact to keep this code as it is ?
    Avoid using of implicit join or Mixup of implicit and explicit join should be avoid to increase the readability.

  • snippet of Noncompliant Code

    SELECT a.test1, b.test1
    FROM tableA AS a, tableB AS b
    INNER JOIN tableC AS c
    ON b.test1 = c.test1
    WHERE a.test1 = b.test1

  • snippet of Compilant Code (fixing the above noncompliant code)

    SELECT a.test1, b.test1
    FROM tableA AS a
    INNER JOIN,tableB AS b
    ON a.test1 = b.test1
    INNER JOIN tableC AS c
    ON b.test1 = c.test1

  • external references and/or language specifications

  • type : Code Smell

  • tags


(Alexandre Gigleux) #2

Hello,

I like the idea to not mix implicit and explicit joins and I think if you activate RSPEC-1741, you will get it.

RSPEC-1741 is asking to join tables with “JOIN” so it basically forbid the use of implicit join.

Can you check if RSPEC-1741 is covering your use case?

Thanks
Alex


(Christian Rohr ) #4

Hi Alex

Thanks for your reply.

Yes that’s the rule - but unfortunately this rule is not available for T-SQL.

Would be great to have it there.

Thank you

Christian


(Alexandre Gigleux) #5

Let’s do it: https://jira.sonarsource.com/browse/SONARTSQL-164 (cc: @alban.auzeill)


(Christian Rohr ) #7

Great, thank you very much :slight_smile:


(Alexandre Gigleux) #8

Hello Christian,

Looks like you have strong experience on TSQL, so I would like to request your inputs.

Do you think the following PLSQL rules could make sense for TSQL:

Thanks
Alex


(Christian Rohr ) #9

Hello Alex

Yes, I’m nearly every day write some T-SQL procedures or queries.

The rules RSPEC-2465/2457 makes absolutly sense, but RSPEC-2521 not, as there is no natural join in T-SQL.

Thank you.

Chris