Execute SQL

There are three separate types of SQL execution provided by RazorSQL. These are execute, execute fetch all rows, and execute all.

The most commonly used type is the execute type. Since the execute option does not fetch all rows at once, but instead waits for the user to request additonal rows by scrolling or some other user initiated action, the execute option performs better than the fetch all rows option.

The execute option determines which statement from the query editor to execute based on certain conditions. If an SQL statement is highlighted in the query editor, that statement will be executed. If there are no statements highlighted, RazorSQL will then check for statement separator defined in the preferences (the default is semi-colon). If there are statements separated by the statement separator, RazorSQL will execute the closest statement based on the cursor position. If there are no statement separators, RazorSQL will attempt to execute the entire contents of the query editor. For PL/SQL, RazorSQL will not parse queries based on statement separators if it determines there are blocks of code, such as begin, end blocks in the editor.

The execute process executes the sql statement. If the statement performs an insert, update, or delete, RazorSQL will attempt to display the number of rows affected in the SQL status panel.

If the query is a select, RazorSQL will display the results of the query in the query results section. RazorSQL determines how many rows to fetch of the query by looking at the fetch size preferences first, and if nothing is specified, by using the specific database driver settings. Most drivers by default have a fetch size of around 100 rows. If the user attempts to scroll to see more than the number of rows fetched, RazorSQL will then try to fetch the next set of rows from the database. The SQL status panel will be updated each time RazorSQL calls back to the database driver to fetch more rows.

Certain database tools only perform actions on the fetched rows. For example, the sort and filter query results option only sort or filter the rows displayed in the query results. If the user wishes to sort or filter the entire contents of the query, the user should use the "execute fetch all rows" option. However, this option should not be used if there are a large number of rows expected to be returned from a query, as very large numbers of rows can cause performance problems.