RazorSQL How to Execute Queries

RazorSQL provides several options for executing database queries based on how many rows the user wants returned, whether multiple queries or a single query want to be executed, etc. See below for more information on the various options.

The first step before executing queries or SQL statements is to get connected to a database. For more information on getting connected, see How to Get Connected.

Execute Options

Execute SQL (One Statement) - This option can be selected using the Execute SQL (One Statement) menu option in the SQL menu, or by using the Execute SQL keyboard shortcut or toolbar icon. This option sends one query or statement to the database. For information on how RazorSQL determines what to send to the database, see below. For this option, results are returned from the database in increments. By default, this is usually around 100 records at a time. When the user scrolls down through the results, if the user gets past 100 records, more records are fetched from the database. The size of records fetched from the database at a time can be changed in the preferences menu under the fetch size option. Since this option only returns a subset of records at a time, it performs better and uses less memory than returning all rows.

Execute SQL (Fetch All Rows) - This option can be selected using the Execute SQL (Fetch All Rows) menu option in the SQL menu, or by using the Execute SQL Fetch All Rows keyboard shortcut or toolbar icon. This option sends one query to the database. For information on how RazorsQL determines what to send to the database, see below. For this option, all results are fetched from the database. If the results are very large, this could cause performance and memory problems. This option should generally not be used for very large tables or queries with very large result sets.

Execute SQL (All Statements) - This option sends multiple queries or statements to the database. If there is no highlighted text, RazorSQL determines which statements to send based on the statement separator value defined in the preferences. The default statement separator is a semi-colon. Each statement should be separated with the statement separator when using this option. If there is highlighted text in the editor, RazorSQL will only parse the highlighted text.

Once RazorSQL parses the contents of the editor and determines all of the queries to execute, each query will be sent to the database separately. By default, if an error occurs, execution halts and no more queries are executed. This behavior can be changed in the preferences.

How RazorSQL determines which query to execute

NOTE: The statement separator value set in the preferences is used by RazorSQL when parsing the SQL editor contents. The default value for the statement separator is the semi-colon. If using a database such as Sybase or SQL Server, many users change the statement separator value from semi-colon to GO.

RazorSQL reads the contents of the SQL editor section (the top-right section of the screen) to determine what query or queries to send to the database.

If there is highlighted text in the editor, if there are no semi-colons (assuming the statement separator preference is set to semi-colon) in the SQL editor, RazorSQL will send the highlighted text to the database with no exceptions. If there are semi-colons / statement separators in the highlighted text, if the preference entitled "Parse highlighted text by SQL statement delimiter . . ." is selected, RazorSQL will parse the highlighted text by semi-colon / statement separator and execute each query separately.

If the user does not highlight any text, and there are no semi-colons (assuming the statement separator preference is set to semi-colon) in the SQL editor, RazorSQL will send the entire contents of the editor to the database.

If there are semi-colons / statement separators in the editor and no text is highlighted, RazorSQL will parse the contents of the editor based on the current cursor position. Any text up to the next semi-colon / statement separator or the end of the editor, whichever comes first, and any text to the previous semi-colon / statement separator or the beginning of the editor, whichever comes first, will be sent to the database.