I'm getting started with SQL. So far, most of my experience is either with simple queries using C# (then performing operations on the data in C#), or designing [relatively] more complex queries with MS Access' design view.
I was recently assigned a task to review a relatively large query (hundreds of rows for a single Select), and there are minimal comments in the code. Also, I'm not familiar with the database being queried. Even though the syntax seems relatively simple, there are so many joins on top of joins that it's hard to wrap my head around.
Ideally, I'd like to have some graphical representation, similar to MS Access' design view. Note that my current position uses SSMS. I'm aware there are tools that can create SQL code from a UML diagram. I'm also aware that there are tools that can create a ER diagram from SQL code (see this question), which is closer to what I'm looking for. Are these ER tools my only option? As far as I can tell, the ER tools only show db relationships, and not specific queries with special types of joins or functions.
Thank you.
If you're using SQL Management Studio (I use 2008) you can just right click on the diagrams drop down in the explorer and click Create New Diagram. I'm not sure if this is what you are looking for but this is how I make all of my ER diagrams for my database.
No, It is impossible to do this by using standart tools like SQL Management Studio or others.
Maybe there exist some specific tools for this.
It is difficult and interesting task to generate joins diagram from SQL query (It is simple for "joins" but how does "union" and "where" clauses should be explained on diagram?)
And I think it doesnt simplify you task.
Related
(sorry - the question wasn't originally clear. I'm not looking for the fastest ways to build insert, delete statements etc, but the fastest way to build queries to alter, for example, tables in the database e.g. adding or removing a column)
So, what's the fastest and best way to build database alteration queries in SQL server? I'm going down the manual route of writing the SQL as it's given me the best result in the past with the IBM Informix database. Points to note:
I've found that using the table designer in management studio is a poor method (in my experience this is too simplistic and GUI driven to be of use, and often requires tables to be completely rebuilt to work well)
The query designer only allows simple select, update delete etc. queries to be built
Any recommended tools that make this easier?
Am I missing something about the SQL management studio that I should know? Seems to create overly complex SQL for building a table, that's difficult to comprehend and edit
Do you write Java, .Net, Python or code by hand? What's the difference with SQL?
If there are patterns and code generation can be automated, (write and) use a code generator (but that goes for the other languages I listed too).
SQL is a lot more than just SELECT ... WHERE ... or UPDATE ... SET ... WHERE id = value.
for most kinds of scripts, I ask SMS to generate the initial script (create, drop, alter, select, insert, delete, execute, etc), and then tweak to taste. not sure if this is sufficient to your needs, but I find it useful
to generate scripts, Right click an object (table/view/sproc/fn/etc) and expand "Script ".
hope that helps.
I have a project where the PERIOD columns defined in the SQL2011 spec are the perfect solution. Unfortunately, I am forced to use MSSQL 2008R2 (or possibly MSSQL 2012) as my database, which does not support this feature.
Is there any proprietary feature that resembles the PERIOD features in SQL2011 currently in MSSQL? If not, any advice for the best way to try to implement something resembling it?
Take a look at Anchor Modelling. I know it's not exactly what you're looking for, (a PERIOD equivalent) but databases implemented as an Anchor model can include bi-temporal aspects. The generated SQL code when exporting the model primarily supports MS SQL. Oracle is available too but a lot of work when into optimizing the schema, trigger and view SQL code for MS SQL. Maybe it'll help, maybe you can see how they implemented bi-temporal data in a way that works really well with MS SQL.
I need to give users the ability to build a simple SQL query against our database. Our application is written in Delphi.
I am assuming only moderate levels of knowledge by the user, but they need the ability to build a simple select statement to be able to query against a couple of tables. If I can make this easy for them, that would be most wondrous.
Does anyone know of a tool or a set of components that I can use to help the users build SQL SELECT statements...
I've used the DevExpress ExpressFilter control to allow users to specify SQL where constraints before.
I've come across FastQueryBuilder http://fast-report.com/en/products/visual-query-builder.html
and
OpenQueryBuilder http://fast-report.com/en/products/free-query-builder.html
(apparently differing versions of the same tool) at Fast-Report.
It looks like the right idea. Anyone have any experience with it?
I've used SimpleQuery for years and am quite happy with it. (http://devtools.korzh.com/eq/vcl/) It's not completely intuitive, but once you get the hang of it, you can present fields to the user from your database(s) and they can combine any series of them with ANDs and ORs to make very complex queries. You get a separate SQL window to save the resulting code. I make The resulting dataset available for printout with PrintDat! or to save as CSV data from the Woll2Woll Infopower grid that I use for display. I occasionally allow for XLS export too with XLSReadWrite. It's all quite automatic at this point. Just take the SimpleQuery example and mold that to your particular needs. You should be able to have something very usable in a day. There is a trial and an example free query builder standalone program that will give you an idea of the final look.
TMS Query Studio? Good value at 75 Euro..
Try EMS Advanced Query Builder.
is a powerful component suite for
Borland® Delphi® and C++ Builder®
intended for visual building SQL
statements for the SELECT, INSERT,
UPDATE and DELETE clauses. It allows
you to build new queries visually
and/or graphically represent the
existing queries in your own
applications. The suite includes
components for working with standard
SQL, MS SQL, InterBase/Firebird,
MySQL, PostgreSQL and many more
dialects. Advanced Query Builder
enables users to make up large and
complicated SQL queries with unions
and subqueries for different servers
without any knowledge of the SQL
syntax.
(source: sqlmanager.net)
(source: sqlmanager.net)
I think the most powerful one is ActiveQueryBuilder, which now included with Delphi IDE (Since 2007 I think)
(source: activequerybuilder.com)
I've written a couple of similar things in Delphi. It's easy enough to allow the user to pick table and column names by querying the metadata and using lists and tree views for display. The difficulty comes when trying to implement things like joins. I've never come up with a good interface for this, and in my experience neither have many of the major data tools players.
You may want to try this free builder:
GSC Visual Query Builder v.0.7
Visual Query Builder v.1.0
and some other in Torry:
http://www.torry.net/pages.php?id=546
My intention is to write a graphical query language where users can drag and drop criteria into a GUI query designer, then the designer will generate appropriate SQL query code and return the appropriate result set. Do you know where I can learn more about SQL code generation or if similar tools like this exist?
You may want to look at Microsoft Access's query designer to see how it works; it's relatively simple to use and you can compare how changes in the graphical representation affect the SQL statement and vice-versa. It should give you a pretty good view of how joins are translated into SQL.
(I cringe to suggest Microsoft Access for anything, but in this case, it might be useful to you).
I'm looking for a tool, which would help creating complex SQL queries. Sometimes it's difficult to even verify, whether the results of a query are correct. It's especially easy to get queries joining several tables to return too little or too much data.
The tool should enable at least creation of test tables, some kind of visualization how the queries gather their data and hopefully give better parsing of error cases than for example Oracle does.
Are there tools like this or do I have to stick with creating test tables manually, filling them with test data and commiting all kinds of queries with SQuirrel SQL?
When you have a very complex query it is usually easiest to validate by breaking it up into multiple queries that populate temp tables. These intermediary results can be individually verified and then you bring them together to produce the final result set. Depending on performance needs you can stick with the temp table approach or you can then rewrite to a single statement. Typically when I have a huge query it is for background processing so I stick with the temp table approach.
What RDBMS are you using? All of the major ones have some type of console available (e.g.-SSMS in SQL Server, Toad in Oracle, MySQL Query Browser/Administrator for MySQL, etc.), and they all have Query Execution Plans where you can see how the query will actually run. So, the answer to your question is that it's entirely dependent on what RDBMS you're using, but the safe bet answer is: Yes.
I recommend trying SQL Server 2008 Management Studio Express (SSMSE) if you are working with SQL Server. I have used it at work and I believe it does everything you are looking for.
You can get it and SQL Server (express editions) here.
Certainly not a free, open-source solution, but I believe Quest Software's TOAD will fit your requirements. Quest seems to offer alot of tools in that space...they have tools for modeling and analysis, however I've never used the modeler or analyzer.
I personally have experience with the commercial version of TOAD for Oracle. It's GUI is overwhelming at first, but after you mentally filter out all of the extra buttons that you'll never use, it's manageable.