Checking SQL syntax

  • Thread starter Thread starter Scott Allen
  • Start date Start date
S

Scott Allen

Hi WF:

You might try sending the SQL command to the database after a SET
PARSEONLY ON command. This instructs the server to check syntax and
return error messages without compiling and executing the statement.

Don't forget to SET PARSEONLY OFF afterwards.
 
Hello,
I don't know if it is the right place for my question but I would like to
know if ther's a way to validate a SQL request before sending it to the
database. I was thinking abut using Regular Expresssion or something like
that .
Thanks for your answer.
 
Thanks for your answer.
More details on my problem.
I'm coding an ASP.Net application and one of the web forms allow the user to
build SQL request using basic field and operators. So the string generated
can look like that :
(field1='test' and (field3 > 10 and field3 < 30)) OR field2 like '%user'
......
I use C# to develop and that's why I was thinking about using Regex.
My purpose is to validate the string before it is sent to the database.
I've searched the net about and found nothing.
Has anybody already done that ?
 
You'll have to check the docs to be sure, but I think
starting in SQL 7.x or 2000 there was a feature to send
the request and have it validated rather than processed.
 
The complexity of the Structured Query Language is so high that it doesn't
make sense to write your own "validator" especially when you can pass the
SQL to the database and have it validate the statement for you.

--- Nick
 
Even if you send it to the database and it validates it as correct, it
doesn't mean that it's guaranteed to run through successfully. It just means
that there aren't any compile-time errors, there may still be runtime errors.
 
Back
Top