Back to articles list
- 4 minutes read

Using Vertabelo’s SQL Script Editor

Vertabelo’s new SQL Script tool lets you write and save SQL scripts and run them against a connected database.

Creating an SQL Script

Start by clicking on the Create Document button. It’s the first one on the main toolbar.

Create Document button


The New Document window appears. Now select SQL script and click on the Create button.

Create button


The New SQL script window will be displayed.

New SQL script window


Name your script using the Name field and click the CREATE button.

CREATE button


Your new script will be opened in the workspace as empty file.

new script


The name of your script is visible in the top left corner of the toolbar. You can see a list of all your scripts by clicking on the drop-down menu arrow to the right of the current script name.

The name of script

SQL Editor Features

SQL Editor provides some useful text-editing features, including highlighting syntax and numbering the lines in your code. It also supports keyboard shortcuts and standard file tools.

SQL Editor

Keyboard Shortcuts

The following table contains a list of the main keyboard shortcuts available in SQL Editor.


ShortcutDescription
Ctrl+ASelect all text
Ctrl+CCopy selected text
Ctrl+VPaste text at cursor
Ctrl+XCut selected text
Ctrl+ZUndo
Ctrl+YRedo
Ctrl+BackspaceDelete the word to the left of the cursor
Ctrl+DeleteDelete the word to the right of the cursor
Ctrl+HomeSet cursor at the beginning of code
Ctrl+EndSet cursor at the end of the code
HomeSet cursor at the beginning of current line
EndSet cursor at the end of current line
Shift+Page DownSelect text below the cursor
Shift+Page UpSelect text above the cursor


You can also double click on a word to highlight all occurrences of that word in your code.

File Tools

All available File Tools are shown next to the name of current script.

The New script button allows you to create a new script.

New script button


You can save the current script by clicking on the Save button.

Save button


You can share your file using the Share button.

Share button


The Download button allows you to download your file to the current workstation.

Download button

Running Queries From the SQL Editor

The SQL Editor allows you to run your query against a database connection. First, you must set the connection by selecting a database from the drop-down list (MS SQL Azure is shown in the example below).

running query against a database connection


If there is a green circle next to the database name, you have successfully connected. If there is no connection to that database, you’ll see a grey circle.

Run button

Once you have connected, simply type your query into the editor and click Run, as shown above.

After the query is executed, a notification will be displayed in the Logs window, located at the bottom of the Script Editor.

Logs window

Transactions

You can also run transactions in the SQL Editor – one way is to simply write the code and run it using the Run button, just like a regular query.

However, the SQL Editor also has a helpful Run within transaction button that launches code as a transaction. This lets you write regular queries that you can run as transactions.

Let’s use the following code snippet to demonstrate. We can select these lines and run them as transaction by clicking the Run with transaction button.

BEGIN TRANSACTION;
		INSERT INTO color VALUES(1,’blue’);
		INSERT INTO color VALUES(2,’green’);
		INSERT INTO color VALUES(3,’red’);
	COMMIT;


Run within transaction button


The Logs window provides information about the progress of the transaction.

Logs window

You can click the Next button to commit the transaction or the Rollback button to cancel it.

Let's rollback this transaction.

Rollback button


We use a SELECT statement, followed by a click of the Run button, to test if data is in the table.

Run button


There are no records in the table. This is what we’d expect because the code was run as a transaction and then rolled back. Now we’ll run the same transaction and commit it.

Commit button


After the transaction was committed, data was stored in the table. Let’s try that SELECT again. The result is shown in the Logs window:

Logs window


You can stop an ongoing transaction at any time. Just press the Stop button.

Stop button

The Logs Window

The Logs window displays query results, error messages, and information about the status of various user actions. Below we see an error message.

Error message


The Logs window has two options: Preserve log and Verbose. The Preserve log shows all the messages from this session. The Verbose box controls the length of the Logs message. By default, the Verbose box is checked. If you choose to uncheck it, log messages will be shorter and less detailed. You can also uncheck the Preserve log box if you don’t want a record of all messages.


You can clear all logs by pressing the Clear logs button.

Clear logs button

go to top