How to execute a SQL script in DBeaver? - 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?

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.

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-synch connection with navigator option that is available from the down arrow menu for the Set active connection from database navigator connection button:
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.

I hope all is well! Great question! I had a similar question when I started working with dbeaver. Here is what I have figured out so far:
run an entire single script with ALT+X;
run selected part of the code or anything before a semicolon, ; with CTRL+ENTER;
run multiple files with Tasks; in dbeaver 21.0:
Click menu Database -> Tasks -> Create new task
Specify task name;
Choose the connection;
Select files to run (I had two to exclude, underlined with red);
Run the task from same menu and watch dbeaver iterate the code for you.
Attached is a screenshot: running a Database Task on dbeaver 21.0

In DBeaver 21.1.3 Community Ed. I can change database and schema by drop down lists on top toolbar. To automatically change it according to selected database in Database Navigator make tick to Window / Preferences / Editors / Auto-sync editor connection with navigator selection.

I just created a New SQL Script (^]) and then hit context menu>File>import SQL Script (Shift-Control-Alt-O). And of course execute it (^-Enter). For dummies like me this isn't that obvious way-of-working.

Related

Create View from logical File programmatically?

The question is about Logical Files (LF) on the AS/400 and views, by IBM i DB2.
I want to know, if there is a way, to programmatically generate an sql statement (or better, directly a view) out of an logical file.
For now, i look up the LF desription (command WRKF ..) and emulate the conditions in the LF.
My knowlege so far, is, that logical files can always be manually(by hand, so to say) converted into SQL selects... but if there is a pitfall, why there can't ever be a programmatic way to do this, i wanna know why.
I'm searching for something like an IBM I method for this, rather to script my own program for that.
Not a programmatic solution but in System i Navigator go to the Schema you are working with and the Views section. Any of these that are logical files you can right-click and select 'Generate SQL'. You can select multiple and it will generate the SQL for all. There is an option to write to a file.

Multiple Window Oracle SQL Developer

I am using SQL developer to access 2 different databases.
I have 2 connections and while working I need to open multiple windows for each database.
How does one do that?
You can right click on a connection and chose 'Open SQL Worksheet' it will create another window for the existing session.
Use Alt + F10and select the connection from the list.
If you need to create another independent session you can use Ctrl + Shift + N for an ongoing session.
In preferences, go to Database > ObjectViewer and check the Automatically Freeze Object Viewer Windows checkbox.
dbardelas answer helped me, the only thing is that he missed where is Database.
Database can be found in tools -> preferences
I had similar issue as victorien sukarieh the only issue I had is that every conexion to a table or database was opened on top of the previous one. It didn't let me visualize multiple tables, with the answer of dbardelas I can open multiple table visualization.

Is it possible to "unprocess" a cube in SSAS to retrieve only the metadata?

I would like to know if it's possible to "unprocess" a cube in SSAS. I want to do this so I can perform a "synchronization" between two differents servers. This (I think), will remove all the data and left the metadata to be synchronized? Am I right?
Do you know a way to do this?
Thanks!
There is the ability to unprocess, although that'd leave your cube unprocessed. Right-click database, select process, in the next window change process type to Unprocess and "Script to new window" in top-right.
If you just want a schema though, can you not script the "Script Database as Create" XMLA? Then drop your target and run the Create XMLA against the target server?

Table doesn't show up in ADO object

I used SQL Server Management Studio to create 3 tables using SQL statements.
Then I attempted to create an ADO object in Visual Studio. The ADO wizard saw my database, but not the tables I created.
Is this because I need to somehow commit the changes I've made in Management Studio?
Or do I need to add some kind of prefix to the table names like:
CREATE TABLE mydb.Table1 ... ?
Or could this be a permissions thing?
Or am I not waiting enough time (1 min or so) for the ADO wizard to grab the table names from the database?
Ah, I guess when you script the creation of your tables (or anything else you're adding) you need to add this:
USE [Interview_MicahHoover]
GO
So much for relying on the ETL guy to set things up ;)
I figured this out by using the GUI to create the table, then right clicking on the new table in the left menu and saying 'CREATE TO ... clipboard', pasting into notepad, and looking at how the SQL Server Management Studio did it.

SQl Developer Single Query result tab please

In the free application SQL-Developer (provided by Oracle), I tried searching around for this but couldn't immediately find a solution. I find the opening of multiple SQL query result window/tabs mildly annoying. I'm sure there are very useful cases for this feature, but my question is:
Can we turn the multiple query result windows to just one (Toad style). If there's a shortcut key for this, that would be super awesome.
SQL Developer 4.0 (2013)
Close all the Query Result tabs
Tools > Preferences
Database > Worksheet > uncheck "Show query results in new tabs"
So, it turns out this is a bug. If you look closely, you'll notice that for each query run, your results tab is automatically being pinned, causing each new query run to need it's own new tab to display the results.
The automatic pinning is only supposed to be enabled when you explicitly go into Tools->Preferences->Database->Worksheet->"Automatically Freeze Result Tabs".
It is an identified bug, that Oracle fixed with SQL Developer 2.1.1.
Go to oracle.com and download the latest version and this should go away. It was definitely very annoying.
Instead of "Run Statement" click on "Run Script"(F5). This would give the output of two queries in the same Query Result window.
Directly to the database or from an application? Do you mean returning one result set from multiple tables together or multiple result sets in one pane? Are you using SQL 2000, 2005, 2008, or something else? The question is vaguely worded, but I'll try to help anyway.
For the purposes of this answer, I think you're trying to query the database directly. Open SQL Server Management Studio 2005 or newer (Not sure if this works in 2000), click New Query, and type the multiple queries into the pane. i.e.:
select * from table1
select * from table2
will return two result sets in the same window/pane.
Unpin helps keep current tab for next query.
(I am using Oracle SQL Developer 22.x)
I found that this was happening in SQL Dev v4.0.2.15 because I was running 2 SELECT statements. Running one SELECT at a time re-used the Results tab.