Nearly 80% of businesses use two or more different database platforms in their workflows. With this growing trend, reusing existing SQL scripts is crucial for efficient development and minimizing errors. The ability to edit and update those scripts helps specialists save time and effort, support legacy systems, and migrate between tools seamlessly. In this article, you will learn three ways to import SQL scripts to DBeaver, which will help you save time and migrate from other tools effortlessly to manage all your SQL code in one place.
When import SQL is needed
Let’s examine the most common use cases for importing and reusing previously created SQL code.
- Migration from other database management tools. One of the obstacles to seamless migration to a new tool is often the large number of scripts that need to be reused or maintained. With DBeaver, it is possible to load the existing SQL scripts, and everything will work properly. You can also read a recent Customer Story from a user who migrated from a legacy tool and kept his old Oracle scripts.
- Sharing scripts between teammates. A fairly common situation is when your colleague sends you a script he created and asks you to check or edit it. The ability to quickly load a ready-made SQL code, check it for errors, and execute it can simplify workflows and collaboration.
- Simultaneous use of the same scripts in several tools. SQL scripts are often part of a multi-component system that software engineers work on. It’s helpful to be able to open and use the same scripts in both a database management tool and an IDE for web or software development.
Method 1: Load SQL file with the main menu
Using the main menu, you can open the existing SQL file from your local disk. To do this, go to File -> Open File. In the window that opens, you can choose any file with the *.sql extension created earlier, and it will be opened in the SQL Editor.
If you prefer a keyboard to a mouse, try the hotkey CTRL+O (CMD+O for macOS) instead of navigating the menu.
With DBeaver, you can open different file formats. Depending on the file extension and the system settings,
it will be opened in DBeaver or by a third-party application.
You may notice that your script has only basic highlighting because it is not associated with the database connection. To fix this, use the dropdown list on the top toolbar to choose the appropriate data source.
Based on the data source, DBeaver identifies the SQL dialect and applies the corresponding syntax highlighting and autocompletion. After opening the script, you will edit the existing file by default. If you want to create a copy of your script and work on it, select File -> Save As on the main menu and save a new file to your disk.
Method 2: Import SQL with the context menu
The second method allows you to quickly load the content of an existing SQL file into the SQL Editor. Unlike the previous method, this one implies creating a new file by default.
Create a new script associated with the specific database connection, open the context menu, and go to File -> Import SQL script.
You can use a shortcut instead of the context menu.
To do this, create a new script in DBeaver and press Ctrl+Alt+Shift+O (CTRL+Option+Shift+O).
Using this method, you don’t need to associate the data source after importing the script. Your new file is already linked to the database connection. To quickly return to it in the future, you can right-click on the connection and go to SQL Editor -> Open SQL Script.
Method 3: Add SQL files in Project Explorer
The third method enables you to load one or more SQL scripts simultaneously. This can be especially useful in cases where your SQL code is part of a complex system, and you don’t want to copy or move your files because they need to be accessible to other applications. Using this method, you don’t create new files but link existing ones on your disk to a specific database connection. Let’s look at how it works.
Go to the Main menu -> Window and choose Project Explorer. The view that opens will show you all the scripts associated with the active Project.
To learn more about Projects in DBeaver, read our blog post.
Right-click on the Scripts folder and select Create -> Link Folder to add several files at once or Create -> Link File to add a single SQL file.
After linking your existing scripts, you can associate them with the database connections using the context menu, navigate through them in the Project Explorer, and make the necessary edits and updates.
Although this method is similar to the first one, it has several advantages. First, you can import not only one file but an entire folder simultaneously. Second, you do not need to open each file to make them available in DBeaver.
Conclusion
When working with SQL, reusing and adapting your existing scripts speeds up development and helps avoid errors. However, getting those scripts to play nicely across different tools can be challenging. As you’ve seen in this article, DBeaver makes it easy to load, reuse, and edit existing SQL scripts. You’ve learned about the three main ways to import SQL in DBeaver and can choose the most appropriate method. To learn more about the SQL scripting capabilities of DBeaver, explore our blog.