I'm building a user interface to be able to execute SQL statements on a SQL Server database, compatibility at SQL Server 2008 R2. I need to be able to determine whether each statement could possibly return a dataset, or if it just needs to be executed. In Delphi, the TADOQuery consists of either Open / Close for a dataset, or ExecSQL just to execute. I need to automatically determine which one to use based on the first word(s) of the SQL statement.
How can I determine which method I should call based on the first word(s) in the statement? I would need to know each possible word, and which method based on each word.
That is not possible in the general sense. EXEC stored-procedure-name for example can eithers return a result set or not, depending on how the proc is written. There is no way to know if it's one or the other just from the syntax of the call.
来源:https://stackoverflow.com/questions/14927761/what-are-all-the-possible-first-words-of-sql-statements