Regular expression to find all table names in a query

前端 未结 12 952
一个人的身影
一个人的身影 2020-12-03 18:09

I am not that hot at regular expressions and it has made my little mind melt some what.

I am trying to find all the tables names in a query. So say I have the query

12条回答
  •  -上瘾入骨i
    2020-12-03 18:56

    RegEx isn't very good at this, as it's a lot more complicated than it appears:

    • What if they use LEFT/RIGHT INNER/OUTER/CROSS/MERGE/NATURAL joins instead of the a,b syntax? The a,b syntax should be avoided anyway.
    • What about nested queries?
    • What if there is no table (selecting a constant)
    • What about line breaks and other whitespace formatting?
    • Alias names?

    I could go on.

    What you can do is look for an sql parser, and run your query through that.

提交回复
热议问题