GET 24/7 LIVE HELP NOW

Announcement

Announcement Module
Collapse
No announcement yet.

Verifying SQL before it is ran

Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Verifying SQL before it is ran

    Is there any way to verify that an SQL statement will run, or is at least syntacticly correct, for alters, updates, deletes, and inserts. I am looking for something similar to 'desc' for selects. It seems like this would be a pretty common thing and I really don't want to try to re-implement the MySQL parser. If anyone could point me in the right direction on this one I would appreciate it.

  • #2
    Use EXPLAIN in front of your query.

    It is used to find out how the execution plan for that query is.
    What indexes it will use etc.

    But it will also need to parse the query in full, so you will get your syntactical test as a bonus.

    Plus you can learn a lot about how to optimize queries.

    Comment


    • #3
      Thanks for the suggestion but 'desc' is an alias for 'EXPLAIN'. It only works for selects. I need something that works for all SQL statements. Any other ideas?

      Comment


      • #4
        The other two suggestions I can give you is:

        1.
        Execute the query with one table name purposely wrong.
        If the syntax is valid then you will only get error 1146: Table xyz does not exist.
        I sometimes do this when I want to make a rough validity check of a sql statement when I'm about to post it as a solution for somebody in this forum.

        2.
        If you are using InnoDB tables then you can execute the query within a transaction which you end by performing a rollback.

        Comment

        Working...
        X