Solved

Analyze SQL Query before Running

Posted on 2006-11-27
3
173 Views
Last Modified: 2011-09-20
Hi,
Is there a way for MySQL to verify that a SQL statement is syntactically and logically correct before running the actual statment? I have a few insert statements that allow form data and I want a way to verify that the SQL is robust and will correctly execute before running the actual query (I'm using PHP also).

--Dan
0
Comment
Question by:dancablam
  • 2
3 Comments
 
LVL 30

Expert Comment

by:todd_farmer
ID: 18021670
You can put EXPLAIN in front of it (assuming a SELECT statement).  That will highlight systactic errors (but not logic errors - you'd probably need to see the results to verify those).
0
 
LVL 30

Accepted Solution

by:
todd_farmer earned 500 total points
ID: 18021690
An example:

mysql> select * from doesnt_exist;
ERROR 1146 (42S02): Table 'test.doesnt_exist' doesn't exist
mysql> explain select * from doesnt_exist;
ERROR 1146 (42S02): Table 'test.doesnt_exist' doesn't exist

It will catch all SQL syntax errors or invalid table/column errors.
0
 
LVL 19

Expert Comment

by:Kim Ryan
ID: 18023470
If you use MySQL query browser it will colour code the query as you construct it, so keywords turn blue, table names red etc.  So you could tell by looking at the colours of the text to see if your syntax is valid.
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Loading csv or delimited data files to MySQL database is a very common task frequently questioned about and almost every time LOAD DATA INFILE comes to the rescue. Here we will try to understand some of the very common scenarios for loading data …
As a database administrator, you may need to audit your table(s) to determine whether the data types are optimal for your real-world data needs.  This Article is intended to be a resource for such a task. Preface The other day, I was involved …
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now