How to execute a SQL script in DBeaver?

Luís de Sousa picture Luís de Sousa · Feb 2, 2017 · Viewed 92.5k times · Source

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?

Answer

simhumileco picture simhumileco · Jul 21, 2017

For larger files, the more optimally it is edit the .sql file in an external editor and then in DBeaver:

  • right-click on your DB
  • chose Tools / Execute script
  • load your .sql file
  • click Start.

This approach is generally more convenient and faster for large files.


To do this without an external editor, you must:

  • set your DB in Active datasource select
  • load your file File / Open file ...
  • run the whole script e.g. using a shortcut Alt+X.