?
Solved

Analyze SQL Query before Running

Posted on 2006-11-27
3
Medium Priority
?
182 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 1500 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

10 Questions to Ask when Buying Backup Software

Choosing the right backup solution for your organization can be a daunting task. To make the selection process easier, ask solution providers these 10 key questions.

Question has a verified solution.

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

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 this article, I’ll talk about multi-threaded slave statistics printed in MySQL error log file.
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses

770 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