I have a sql file saved off that I want to open and get results back from a database I am connected to in DataGrip. When I open the file, it opens it up as a file scope, and not as a console scope, and I cannot run the sql against the database. I have to open up a new database console, copy my SQL into the database console, and run it from there. Make any changes I want to the SQL, and save it back to the file. I just want to open the file up as a console.
I have to be doing this wrong. What am I missing? How can I open a SQL file from disk in DataGrip and execute the query in a console-like fashion?
Example: I have a SQL file: "customer.sql" that contains "Select top 10 * from customer". When I open up "customer.sql", it opens up as a file in DataGrip with no execution or associated database relationship. I want to run the "customer.sql" contents of "select top 10 * from customer" against one of my database connections. Make my changes to the query "select top 11 * from customer" and save it back to "customer.sql"
There is a new option in DataGrip 2017.2 : Attach console.
You can find via Ctrl+Shift+A or by opening the context menu for a file. After performing this action, this file can be run against the console. Switching consoles will be useful if you want to run the same script in several data sources.
Here is the documentation from "Running SQL Script Files" help page for DataGrip 2016.3 to run your own file and get results, as if running SQL from a console.
It appears that any changes to your file are saved automatically, even if the script is not executed, and then previous versions are available through "Local History" which is a feature of most if not all of the JetBrains IDE's.
When running individual statements contained in an SQL file: – The statements can contain parameters. Prior to running such statements DataGrip will ask you to specify the parameter values.
On the other hand: – The statements are run for only one data source at a time.
Place the cursor within the statement you want to execute. If you want to run more than one statement, select (highlight) the necessary statements.
Do one of the following: – Press Ctrl + Enter or select Execute from the context menu. – Press Alt + Enter or click the Intention Bulb, and select Run query in console.
Select the database console to be used.
The statement or statements are executed using the selected console. The corresponding console is associated with the file. The name of the associated console is shown on the Status bar.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With