In this tutorial you will learn how to use Sohag Builder to execute and generate SQL queries.
This tutorial uses SQLite version of chinook database, you can download it from here.
You may follow the same steps using any other database.
Connect to database.
Write, generate and execute queries.
1- Connect to database.
Hit connect button (first button in the toolbar), or use file menu to connect to database.
From the connection dialog choose SQLite from the database type list. Use browse button to set the database location.
Press the connect button. The connection dialog will disappear and the database info pane will be opened at the left, The database info pane contains a list of database tables and views attached to their database schema.
To open a new Query tool, press the SQL button the second button on the toolbar.
The Query tool is constructed of three parts. SQL Editor at the top, control buttons at the middle and the result pane and SQL history pane at the bottom.
2- Write, generate and execute queries.
Now write the following query in the SQL editor.
SELECT AlbumId,Title,ArtistId FROM main.albums;
Sohag Builder displays an auto complete list for SQL reserved words after writing the 3rd letter in the word .
To display the list manually press Ctrl+Space key combination
Now press Execute button or F5 (Also Execute from the Query menu will do the same functionality) to execute the query.
A brief description about every executed query appended to the result summery .
Query Tool adds a new tab contains the result of every SELECT statement.
Query Tool can generate SQL statements (SELECT, INSERT, UPDATE, DELETE, DROP), to generate statements select the table or view first from the database info pane and then press F8 for SELECT, F9 for INSERT, F10 for UPDATE, F11 for DELETE and F12 for DROP or press the button that corresponds to the operation you want to execute at the bottom of the database info pane.
You also can generate SELECT statement by activating the table or view name in the database info pane (mouse double click or using Return key).
Generated statement will be appended to the end of SQL editor for the current Query Tool, If the current tab is not a Query Tool or no Query Tool is opened a new Query Tool will be opened first.
Every Query Tool has it's own database session.
3- Other functionalities.
1- Execute Once.
This option determines the query execution mode, Query Tool has two modes to execute the SQL editor code.
A- Single query mode (When Execute Once is checked).
In this mode all SQL Editor contents are executed as one query (will be sent to the database as one block without any processing).
B- Multiple query mode (When Execute Once is unchecked).
In this mode the SQL Editor contents are processed to remove white spaces, comment blocks then divided into queries to create a query queue which is executed one by one, multiple query mode is the default mode.
To add multiple queries every query must end with semicolon ; followed immediately by a new line.
This will clear both SQL editor and results pane, SQL history will not be cleared.
To commit the current transaction.
To rollback the current transaction.
Every Query tool starts a transaction at opening.
COMMIT or ROLLBACK commands ends the current transaction and starts a new one immediately.
Loads SQL file from the file system.
Saves the contents of SQL editor to the disk.
Exports the current SELECT result tab to CSV format.