Your first queries in the SQL Editor

SQL Editor is a powerful tool for creating and executing various SQL scripts. Today we are going to tell you about its main features.

With the SQL Editor you can write and execute scripts, save them as files and reuse them later. To create a new SQL script or to open an existing one, go to the main menu, click SQL Editor and select an appropriate option. Here you can also open a recent script.

If you have not selected a specific database, a window will appear which will prompt you to choose a connection.

Many of our users prefer to write scripts in the SQL console, which is a possibility DBeaver provides. As scripts written this way are not saved in a file format, in some cases console is faster and more convenient to use.

The SQL button above the Navigation tree allows you to open SQL scripts, as well as change the default command. For example, you can set up a quick opening of the console by clicking on this button.

You can use the SQL Editor for executing full scripts and single queries like SELECT, INSERT, DROP etc. By default, each new script will open in a new tab, which you can change if you want.

The editor highlights keywords, which is especially useful for large scripts.

Different databases have different sets of reserved keywords and system functions, so highlighting depends on the database associated with the script.

You can change the editor settings according to your personal needs. To do this, click on the gear icon and go to Editors -> SQL Editor. Here you can change the formatting, script processing settings, and more. For example, here you can change the work of the code completion which is one of DBeaver’s most useful and convenient features.

The SQL editor also has a right-click context menu with a lot of options. For example, to convert a case, you need to select a part of the script, right-click and go to Format -> Upper case or Format -> Lower case.This feature can be useful when dealing with case-sensitive databases.

Let’s try to write and execute a couple of simple queries to demonstrate the essential features of the SQL editor. We will use our test database. Working with any of your tables will be the same.

Imagine that you own a shop and store your customer data in a database. You can use queries to quickly analyze purchase statistics. Let’s execute a Select query to show only those Billing addresses for which the Total value is greater than 10. Enter query, then click on the Execute button. As a result set, you will see a table in the Data Editor.

You can perform many operations on this table. Don’t forget to read our article about the Data Editor

You will not see the result in the table form for some query types. For example, if you run the insert query, you’ll see a message about the changes you’ve made or an error message.

Let’s check that our query worked and the row was added to the table. To do this, we need to execute a Select query.

As you can see in the result set, there is a new row in the table with the correct data.

In the same way, you can write and execute various queries and work with different SQL scripts by using SQL Editor.
To learn more about all the features of this tool, check out our Wiki.

We hope this tutorial was helpful for you. We will be glad to see you again on the new DBeaver’s blogposts.

Author: