Set parseonly
Check the syntax of each Transact-SQL statement and return any error message without compiling or executing the statement.
Set parseonly {on | off}
When set parseonly is on, SQL Server only analyzes statements. When set parseonly is off, SQL Server compiles and runs the statement.
Set parseonly is set during analysis, rather than during execution or runtime.
Do not use parseonly in stored procedures or triggers. If the offsets option is on and no error occurs, set parseonly returns the offset.
Set noexec (TRANSACT-SQL)
Compile each query without executing the query.
Set noexec {on | off}
When set noexec is on, SQL Server compiles and processes each batch of transact-SQL statements but does not execute them. When set noexec is set to off, all batch processing is performed after compilation.
SQL Server contains two phases: Compilation and execution. This setting allows SQL Server to verify the syntax and object name in the code when executing the transact-SQL code. It can also be used to debug some statements that are usually in a large batch.
Set noexec settings are set during execution or runtime, rather than during analysis.
Set parseonly code:
public bool ValidateSQL(string sql){bool bResult;SqlCommand cmd = _conn.CreateCommand();cmd.CommandText = "SET PARSEONLY ON";cmd.ExecuteNonQuery();try{cmd.CommandText = sql;cmd.ExecuteNonQuery();bResult = true;}catch (Exception ex){bResult = false;}finally{cmd.CommandText = "SET PARSEONLY OFF";cmd.ExecuteNonQuery();}return bResult;}