Search code examples
dbeaver

How to execute a SQL script in DBeaver?


I have a number of .sql files that I wish to execute through DBeaver. Traditional database development programmes allow the user to edit and run SQL scripts (totally or partially) in the same window, but this is not obvious with DBeaver.

When I open a .sql script some drop down boxes in the button bar appear, that seem to serve as connection selectors. But none of the connections I have defined appear in these drop down boxes. It is possible to open a SQL console on database objects in the Database Navigation view, but not on SQL scripts.

How can I execute a SQL script, totally or partially, against a particular database connection with DBeaver?


Solution

  • I believe I figured how to do this. First of all, the desired script must be open with the SQL editor. Then one must select the Auto-sync connection with navigator option that is available from the down arrow menu for the Set active connection from database navigator connection button:

    enter image description here

    In certain cases, this immediately activates the SQL console within the SQL editor panel. If that is not the case then one must go through the Database Navigator and select the desired schema on which to work.

    It is then possible to execute a segment of a SQL script (e.g. a query) by selecting it and pressing Ctrl+Enter.