Solved

Analyze SQL Query before Running

Posted on 2006-11-27
3
176 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

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction In this installment of my SQL tidbits, I will be looking at parsing Extensible Markup Language (XML) directly passed as string parameters to MySQL 5.1.5 or higher. These would be instances where LOAD_FILE (http://dev.mysql.com/doc/refm…
Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

803 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