Xavinou
Xavinou

Reputation: 802

Prepare a syntactically invalid query

I want to check the syntax of a SQL query. I thought to do in preparing it, with DbCommand.Prepare method.

Unfortunately, no error or exception.

For example: SELECT * FORM table

Is there a way to check the syntax without executing the query ?

To make it perfect, it has to work on SQL Server, Oracle and IBM DB2

Upvotes: 0

Views: 196

Answers (2)

Damien_The_Unbeliever
Damien_The_Unbeliever

Reputation: 239724

For SQL Server, you can use SET FMTONLY and/or SET NOEXEC

set fmtonly on
go
SELECT * FORM table
go
set fmtonly off

Upvotes: 2

Ernest Friedman-Hill
Ernest Friedman-Hill

Reputation: 81704

Generally only the database you're using is going to know whether a given query is valid or not. One standard and portable trick is to add a WHERE clause that guarantees nothing will be done, then execute the query; for example execute SELECT * FORM table WHERE 1=0 and see what happens.

Upvotes: 2

Related Questions