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
Solved

Analyze SQL Query before Running

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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
MySQL Init Waits 25 119
SQL inner join confusion 15 55
A query works with MySQL 5.6, mariadb 10.1 but fail on MySQL 5.7 6 47
Using cfstoredproc to return query data 2 30
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 …
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
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…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

856 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