Are there tools that can execute a SQL script one statement at a time? - sql

When I have to run database migration scripts, I tend to exercise a large degree of paranoia and not run the script all at once like dbcli < migration.sql. Instead, I prefer to run the commands one-at-a-time. So far, I've just been using copy/paste which is miserable.
There has to be a tool that can do this kind of thing, but I'm having a hard time finding one using Google, Wikpedia, or StackOverflow (close but no cigar).
This is definitely something I could write myself, but it just has to exist already, doesn't it?
This really needs to be something that can be run from a command-line with a tiny bit of interactivity (like display the statement that will be executed, let you press e.g. ENTER to execute it, then show you the output if there is any) since servers usually don't have any GUI available.
My specific db target is MySQL but there's no need for such a tool to be db-specific.
Update
Meanwhile, I'm writing a utility in Java that will do what I want.

Oracle SQL Developer will run one line at a time as long as it's ended with a semi-colon.
You can connect to certain 3rd party databases with additional drivers (http://www.oracle.com/technetwork/products/migration/omwb-getstarted-093461.html)

You could try dbForge. There is a free Express Edition, but I can't quite tell from the feature comparison list if it allows you to step through arbitrary SQL scripts.

Emacs' SQL mode supports sending line by line, region by region and file by file.
Of course, you have to learn emacs, but it does do what you want.

Long ago, I wrote my own tool for this purpose, and have been using and perfecting it over time. Feel free to use it and offer suggestions for features, etc.

Flyway Teams Edition (commercial license) also supports executing statements one by one under Stream parameter. This is not an exact answer to your question, but it can at least give you information about existing tools.

Related

Redgate SQL Prompt equivalent for PostgreSQL database

I'm starting at a new company after coming from a previous role where I could rely on Redgate's SQL Prompt with a MySQL environment. I'm now working with a Postgresql environment (SQL Workbench/J) and was wondering if anyone had come across any similar programs for Postgresql to make the query writing a bit less tedious and time intensive.
I'm aware of the CNTRL + Space option for suggesting columns/tables, hoping for something that automatically prompts.
Thanks!
You can use the dbForge Studio for PostgreSQL software to meet your needs, and this will help you to use this software in accordance with what is in the SQL Prompt program.
I hope the explanation I gave was useful to you.
A full-featured GUI tool for PostgreSQL is pgAdmin.
Among many other useful features, it has a query tool with code completion and suggestion.

SQL Code Push, Tracking and Auditing

Just a bit of background on where my question is coming from: my company has multiple databases across the globe that uses the same schema and once of my department's responsibility is to monitor and make sure all these DBs are in sync from a schema SQL change perspective.
Now, my question is if anyone knows of any Software/tool that has a a Frontend UI which is able to do the following (the lower number the more important to have):
Able to track what SQL code change was applied on which database and when. Basically, if we write a SQL query that changed the structure of a table and we need it applied to 80% or 100% percent of the DBs, either via manual input or some automatic check the tool will tell me that yes, this was indeed applied.
Code distribution tool: we give it the query or a file that contains the code and it's able to push to the Databases it needs to (and create the audit log for that)
Code/object repository: keeps track of what was custom developed and pushed to the databases
I know SSIS might be able to do some of these things, but we need a tool that also has a simple frontend interface that can be accessed by non-IT personnel. (*clarification: we are not planning on giving non-DBA people access to change things, just to the audit aspect of said tool)
I've tried searching the internet, but i have a feeling i'm not using the right vocabulary to get the results i'm looking for.
Hence i wanted to see if the community was aware of any such tool or something similar?
Try searching for one of these two types of systems:
Release/Build/Deployment Automation Complex programs like Serena that have modules for pushing, tracking, and auditing any kind of software, anywhere. These will include all the GUI bells and whistles. But you'll have to deal with extra databases, configuration, agents, workflows, consultants(?), etc. These programs are geared more towards developers.
Remote Execution/Configuration Management Simpler programs like Salt, Fabric, and Ansible that let you run operating system commands anywhere. They don't offer as many features, and you have to do more of the work yourself, but in some ways that's liberating. If you know exactly what commands you want to run you don't need some other program holding your hand. These programs are geared more towards administrators.
From a database administrator's point of view, the main problem with those types of programs is that none of them are relational. Yes they can connect to a database and run a script, but none of them really speak SQL. Their native languages are Java, XML, SSH, etc. There's nothing wrong with those technologies, but if you only care about databases you don't want to deal with all that complexity.
If you're not happy with either of those types of programs I recommend you look at my open source program Method5. It is a remote execution program built as an extension to Oracle SQL. It works entirely inside an Oracle database, so you can install it yourself and won't need any additional websites, agents, configuration files, GUIs, etc.
Based on your comment about getting bogged down by links, and my answer to your question about half a year ago, I think this is the kind of program you were gradually heading towards creating. It took my team a couple thousand hours of developing and testing to get it right so you were probably wise to give up on making your own.
To specifically answer your requirements:
Tracking Changes are stored in an audit trail. But more importantly it has the ability and a pre-built script to compare an unlimited number of schemas, all in one view. At the end of the day what you really want to know is "are my schemas the same", not necessarily "did the same thing get run everywhere?".
Code Distribution If you just have SQL or PL/SQL, deploying it through Method5 is as easy as it can possibly get. Just specify what you want to run, and where you want to run it, like this: select * from table(m5('create index ...', 'dev, qa, prodDB1, prodDB2')); The program does not (yet) run SQL*Plus scripts. But when you have the ability to run SQL and PL/SQL so easily there's little need for SQL*Plus.
Code Repository All executions are stored in a simple table, M5_AUDIT. It contains the code, who ran it, where they ran it, and how they ran it. It wasn't designed to be a repository like SVN but it's good enough for simple auditing and tracking code.
Method5 does not contain a GUI but in some ways I consider that to be a feature. Since everything is done relationally, everything is in a simple table. You can use any of your existing GUIs - Toad, PL/SQL Developer, Excel, Apex, etc. It's a robust back-end solution that will hopefully make a good foundation for easily building a simple front end.

what method is the most used and efficient to copy "database schema" to other servers not the db!

servers all sql server 2008, and win xp
i have the following task
create a huge database, DONE
distribute it to the 20 waiting servers!!
if there were two or three i would have taken the trouble of creating the db's on all of using sql server managemnt stdio
but i am guessing that there is an efficient way
please note,
only the copy of the database structure, the schema is needed not the values within the cells!
thank you

			
				
Or of course you should have been creating the scripts as you went along and putting them in Source control. Then you would have exactly which scripts you needed for this version of the software and be used to doing the same thing for later modifications. You would also script the data inserts for any lookup tables you need to build.
Not having that, you can script the entire database. or use a SQL compare tool. But I strongly urge you to start treating database code like all other code and scripting, storing it in source control and versioning it. Life is so much better when you do that.
What Gabriel McAdams has shown, or, Redgate SQL Compare does this very nicely also.
If you can spare the moolah, using a tool like Red Gate's SQL Packager is an option i have used in the past and it works well!
The tool can do a lot more as well and may not be worth the spend though if you do not need the other features!
In that case, Gabriels'option above is definitely the easiest one to go with!

Scripting your database first versus building the database via SQL Server Management Studio and then generating the script

I had a (friendly but heated) argument with my lead developer the other day because our project has TSQL Scripts that I code directly into SQL files which I then run against the database. I find that when I do this, it's easy to work out the schema in advance without fiddly pointing and clicking and then there's no opportunity to forget to generate a script to put into source control as generating the script no longer becomes a chore you have to do after the fact, but is an implicit part of the process (and also leads to cleaner scripts without the extra crap that SQL Server Management Studio inserts into the scripts it generates).
My lead developer insists that having to manually script it out is a pain in the arse and that he absolutely refuses to write his scripts by hand when there are perfectly good tools to do it without coding. I've noticed that the copying of his changes into the actual scripts tends to get delayed a bit as a result though.
What are your thoughts on the pros and/or cons of doing it one way vs the other? Am I being too rigid/old-school in my sticking to hand coding schema scripts or is he being too reliant on third party tools and losing something in the process?
I always script stuff myself because the wizards sometimes don't script things in a way that I like it and will also give funky names to defaults
scripting things yourself is also good in case you get laid off and you have to go for an interview where they ask you to script DDL on the whiteboard
As I usually collaborate with a colleague during the schema design, I tend to design the schema using the GUI tools, as its easier to discuss it with a diagram of the tables in front of you. I then generate the scripts, being careful to select the exact options that I want to avoid having to make manual changes post-export.
I think a decision on the relative merits of the two approaches might take into account factors such as
the frequency of changes to the schema
the frequency with which changes need to be propagated to other schemas (test, user acceptance, production, clients * n, etc)
the degree to which the schema may vary across development branches
how well-known in advance your various changes can be scheduled
whether or not you can generate SQL "diff" scripts between schemas.
On balance, I tend to prefer to work with a script for each change (or "migration"). It lets me resequence change releases as priorities shift.
Just because you can create tables in a graphical tool doesn't necessarily mean you should.
I find its as quick to write a script as it is to use SQLMS. You still have to type names in SQLMS, and the time spent moving from keyboard and mouse could be used writing the proper script anyway.
The two of you are almost working with two sets of code. Consistency seems to be a key factor on these types of decisions. In your case, if you create a script, your boss uses the gui to add a field, how do you stay in sync? You can't use your script to rebuild the table without editing it (Chance for error.).
Maybe he should pull rank and force you to format your scripts the same way the GUI creates them - just kidding.
I think you should flip on it..........

What do you use to write and edit stored procedures in Oracle?

There are many options for editing and writing Stored Procedures in Oracle; what is the best tool for you and why? (one tool per answer.)
Tool for Oracle Application Developers (TOAD), from Quest Software (formerly TOADSoft) has an excellent Stored Procedure editor with syntax highlighting, some autocomplete support (e.g. type in 'TABLE.' and the columns will appear), a nice Execute Procedure option that will show the results in a Grid or show DBMS output, and will also focus on syntax errors when you hit compile.
Note: The Freeware edition only allows 2 concurrent connections to the same Database Instance (even though the website says 5) - that means only 2 developers or DBA's can use it at the same time on the same Database. It also expires every 3 months but they're good at releasing updates.
I recently found the free Oracle SQL Developer.
nice looking GUI (makes you not poke out your eyes like the usual Oracle tools)
has many nice features, like showing tables filtered
lets you connect to multiple oracle instances at once
you can use sane configuration like ip:port username/password and do not have to use those strange TNSNAMES.ORA file based settings
you can set breakpoints and step through the code of stored procedures.
PL/SQL Developer from Allaround Automations.
I happily paid the $200 or so price for this.
Excellent IDE (+ good Intellisense, + debugging capability) with easy creation and editing of PL/SQL packages, SPs, Triggers etc
So much better than Toad.
Toad, from ToadSoft.com -> http://www.toadsoft.com/toad_oracle.htm
For someone like me who likes to work with a DBA tool like Microsoft's SQL Management Studio, it's a life saver.
As a professional PL/SQL developer I use (heh) PL/SQL Developer from Allaround Automations.
I've worked with TOAD for quite a long time but now it is quite overpriced comparing with PL/SQL dev. It has some advantages like knowledge base or ability to work with other RDBMS like SQL server but that's not a necessity for me.
But Notepad++ will always help to make occasional fix.
I always use PL/SQL Developer from Allround Automations.
http://www.allroundautomations.com/plsqldev.html
But some at our place swear by Toad
Use Oracle's own SQL Developer. If you are mainly working with Oracle, it does everything you'll need.
I use TOAD with our Oracle reports development, and I think that it's a good development tool. I normally toggle back and forth between a number of different Oracle instances and schemae, and I like the way that TOAD can display multiple windows for each instance/schema, or even more than one per schema.
TOAD takes a little while to learn and customize, but it's a worthwhile investment. The layout is similar to the Visual Studio .NET IDE with sidebars that can be anchored or rolled away. Tabs display different aspects of the Oracle schema, including procedures, jobs, stats, etc. And when I'm writing SQL, the editor uses color-coding and the error messages are Oracle-specific.
Toolset for Oracle (TOra) is a free, Open Source Database Tool very similar in scope (and look and feel) to Quest's TOAD
Compared to the freeware edition of TOAD, TOra allows multiple connections to different database instances at the same time, and has no concurrent connection limit (so any number of TOra users can be working on the same database instance)
I just used a standard editor (vim which then gave me syntax highlighting).
/Allan
I like SQL Developer from Oracle. Oh and its free! :)
I like Rapid SQL, you can debug SQL too
Notepad++ stays my favourite editor. I had to use SQL Developer in the past, it's not so "bad", but I encountered many problems with it. It proved very unstable so I wouldn't recommend it, or maybe only to test your procedures.
I use JetBrains IDEA (a Java IDE) to edit and SQL*Plus to execute. The advantages of using a tool with local version control, seemless integration into Source Version Control, advanced find and highlighting, great editing, 'live templates' and so on for me outweighs any advantage of having it 'database aware' (which with plug-ins you can get anyway). If I was coding up a complicated query I might fire up SQL Developer, but generally I prefer great text editing features.
I use Oracle SQL Developer - the latest version also has support for CVS and Subversion.
It has the bonus of supporting other database providers, too.
I have used this tool for 2 years and it has now settled down to be reliable.
I've used RapidSQL by Embarcadero on several different DB platforms, and it's awesome. It has an integrated step debugger, too. I haven't actually used it with Oracle, but I know it's supported.
Another vote for Oracle SQL Developer. It's free, it's stable and it does all the basics that I require.
With the mentioned SQL Developer you can even set breakpoints and step through the code of the stored procedure.
Yet another vote for Oracle SQl Developer. But TOAD works too.
A really good text editor with syntax highlighting (e.g. Textpad from www.textpad.com) and SQL Plus.
For me its, Oracle SQL Developer. The learning curve is very minimal if you have worked on IDEs like Eclipse or VS. You can set break points, read live values when you debug stored procs as you would do to code in eclipse/VS.
Ofcourse the UI is a bit sluggish at times but given that its free compensates the sluggishness.
I use Textpad, Clipmate and Quest SQLNavigator. The newer versions of Quest's SQLNavigator and TOAD are crap -- they tend to crash easily and don't play nice with XP/Vista/Win7.
I've spent hours with their tech support and they don't have alternatives.
You get no access to Quest programmers, but rather you get bogged down in their
trouble ticket process.
Quest needs to focus less on integration of different tools into one and selling you
promises that the next version will solve the instability issues.
They need stability.
This means cleaning up their existing codebase or starting over.
More competent programmers, fewer salespeople, fewer tech support people.
Fix the damn problems.
They focus on sales and it's an idiotic business strategy.
This seems to be a problem across the industry.
Quest's TOAD and SQL Navigator have become bloatware and will soon become abandonware
if they don't turn them around and make them more stable.
I copy and paste frequently between Textpad and Quest SQLNavigator because SQLNavigator
crashes and I lose all my sql code up to the point of crash.
I'll probably dump SQLNavigator once I find something more stable.
SQL Developer from Oracle
We have replaced all other tools at our (large well known) enterprise that has over 150 databases and it works just fine. It's not as good as TOAD but it is getting there, and (unlike TOAD) it's free.
SQL Developer also works well enough connecting to SQL Server