I am using Intellij 14.1.4. I am able to run SQLs by custom defined db data sources in database console.
I have some sql files in my project and would like to execute them directly instead of copying them to the database console. However, I am not able to use the same data sources that I created for the console when setting up connections from the DB Connections drop down.
I wonder how to run SQL statements from sql files with the same data sources as the ones I defined in the db console?
Thanks
You can right-click on an sql file in the editor and there is an option "Run myfile.sql"
To run SQL statements from sql files You must associate with file type
see how
Related
I have a few SQL queries to run in Microsoft SQL Server Management Studio 2018 to export data as .txt files. The .txt files are then imported to ElasticSearch via Logstash. At the moment, I'm running these queries manually via a many clicks operation:
Right click on the database
Click Tasks > Export Data
Choose my data source from SQL Server Native Client 11.0
Choose my destination as Flat File Destination.
Type my desired filename to store in the output folder.
Choose to Write a query to specify the data to transfer Copy and Paste my SQL Statement Finally a few next buttons and run it.
My question is, is there an API or a way to automatically run these queries periodically (once a day at 12 pm), and store it in a particular folder?
Thanks
You can save the Export defintion as an SSIS package
If you're running on your PC then you can run SSIS from a scheduled a task using DTExec
If you're running it on the SQL server than you can configure a SQL job
You can try one of the following:
SQLCMD command line SQL tool to send your query output to text file using -o switch. it can be scheduled using SQL Server Agent Job
Or you can use the SQL Job Step Advanced tab to specify an output file to receive the out from your job step.
I'm looking for a way to script out an entire SQL Server 2015 database to write table creation scripts, stored procedure scripts, triggers, etc etc to a folder so I can set a baseline for a TFS repository solution. Apart from manually exporting each script one by one, is there a way to do a bulk export?
Obviously I'm not talking about data here, I'm talking strictly about exporting creation SQL file scripts to a folder for a single database.
Please try with SQL Server Management Studio.
To open the Generate and Publish Scripts Wizard. In Object Explorer, expand Databases, right-click a database, point to Tasks, and then click Generate Scripts. Follow the steps in the wizard to script the database objects. On the Choose Objects page, select the objects to be included in the script.
https://technet.microsoft.com/en-us/library/ms178078(v=sql.105).aspx
you can generate sql scripts in ssms by following steps:
Right Click on the Database
Go to task and then Click on "Generate Scripts..."
follow the wizard steps to create scripts
I have exported database from Oracle SQL developer tool into .sql file. Now I want to run this file which is of size 500+ MB.
I read about running scripts here, but I didn't understand the way. Is there any command or query by which we can run this sql script by providing path?
You could execute the .sql file as a script in the SQL Developer worksheet. Either use the Run Script icon, or simply press F5.
For example,
#path\script.sql;
Remember, you need to put # as shown above.
But, if you have exported the database using database export utility of SQL Developer, then you should use the Import utility. Follow the steps mentioned here Importing and Exporting using the Oracle SQL Developer 3.0
You need to Open the SQL Developer first and then click on File option and browse to the location where your .sql is placed. Once you are at the location where file is placed double click on it, this will get the file open in SQL Developer. Now select all of the content of file (CTRL + A) and press F9 key. Just make sure there is a commit statement at the end of the .sql script so that the changes are persisted in the database
You can use Load function
Load TableName fullfilepath;
I have a SQL Server database for which I want to generate script of data as well as schema both. I tried Tasks -> Generate Scripts -> Script all objects in the selected database but it does not give the .sql for the data itself.
How do we generate the .sql database for both data as well schema? Please suggest some easy method such as a tool or something that can be used easily
Backing up/Exporting database
There are two ways to Back up/Export a SQL Server database using SQL Server Management Studio:
Right click database → Tasks → Generate Scripts → Choose DB → Change “Script Data” option to true → …
Right click database → Tasks → Backup → ...
The first method creates a .sql file that then we need to run. The problem with this method is that the .sql file can be too big to be opened with SQL Server Management Studio. In that case we need to use the sqlcmd utility (should be already installed if we have SQL Server MS). Instructions below.
The second method creates a .back file that is then easy to import into an empty database.
Importing Database
If we have a .sql file and it’s not too big we can just open it with SQL Server MS and run it.
If we have a .sql file but it’s too big to be opened with SQL Server MS we have to use sqlcmd like this:
>sqlcmd -i C:\panels_QA28July11.sql -o C:\PanelsImportResult.txt
The parameter after -i is the file to import. The parameter after -o is where to save the output. We can omit the second parameter if we want to see the process on the screen.
By default it will use the local machine and local database server. If we want to use a different machine and server we use the -S option.
Right Click on db => Tasks => Generate Scripts => In "Set Scripting Options: Click Advanced, find Types of data to script. You can choose between Data only, Script and data and Schema only. The default is Schema only
Images talks better than words, :)
I've a list of .sql script files to create Stored Procedures which I'm using the Eclipse DTP to develop. Currently to create/update all these Stored Procedures, I've to open & run
one by one from the Data Perspective.
Is there a way to create a batch file that run the scripts along the lines of
run createSP1.sql
run createSP2.sql
...
run createSPn.sql
and run it in the Eclipse DTP to avail of the DB connection defined there?
why not just create a batch file that merges all of your .sql files together into a single procs.sql file as part of the build process. I don't know what platform you're running on but in Windows you could have a .bat file that does something like this:
type *.sql > proc.sql
then to apply it to the database, why not do it outside Eclipse and connect to the database via the command line. You could bundle this all up as a single batch file that gets the latest version of your stored procedures from source control, merges them into a single file and then applies it to the database.
Part I
As far as I know the developers of Eclipse DTP
have not yet implemented a command line SQL execution
interface through the Eclipse console view.
See the following URL on the eclipse DTP developer forum
http://dev.eclipse.org/newslists/news.eclipse.dtp/msg00304.html
Part II
While the Eclipse DTP people are working on it,
you can use a database specific tool to load
a master SQL file (all SQL proc files
appended together)
There are database specific console
tools that will load your master SQL file
command line.
(ie. SQL*Plus for Oracle, ij for Apache Derby)
Part III
An improvement over DOS batch is using Cygwin bash
or python or perl to merge all of your sql files
together into a master file.
I found that the text processing tools available
in UNIX (awk,sed,cat...) are great for this sort
of thing.