Generating DDL and documentation from ER-diagram - sql

Looking for a way to have 3 artefacts in sync:
SQL DDL for creating schema tables
Diagram presenting tables, columns and relationships
HTML documentation describing tables and columns,
at least column name, data type and comment/remark
Ideally, there should be one master format from which the others can be generated.
Generating diagrams from other formats usually leads to ugly, not-too-friendly results.
So, is there any tool supporting
drawing a schema diagram, allowing me to define comments/remarks on columns
exporting SQL DDL for creating tables in DB
generating HTML documentation. This is optional, if column remarks can be included in DDL (e.g. "column1 integer, -- my remarks"). Converting DDL to HTML is trivial.
My environment is DB2 9.7 LUW.

IBM DataStudio allows you to generate ER diagram from scratch, or by reverse engineering. IT does not have a sync capability, however it has the option to keep track of your changes.
Also, Data Studio can extract DDL from the database and generate DDL from the current objects.
The HTML generation is not included, but it sounds a very nice feature. However, you can use the COMMENT command in order to include your remarks as part of the DDL.

I tried few tools so I decided to share my experience:
MS Visio Professioinal 2010 ; without extensions, you can not export DDL. I tried Forward Engineer Addin, but that lead to very MS SQL specific result. I've heard that some older versions of Visio can export DDL but I couldn't try.
IBM DataStudio ; very exhaustive installation (1250 MB), Eclipse based tool. This did the job but felt like overkill.
MySQL Workbench 6.1.4 CE ; Handy, responsive tool with reasonable footprint (125 MB). With few minutes try, I had drawn an ER-diagram and exported it as DDL and SVG. And the result was good quality.
My choise is MySQL Workbench. It's open source and seems easy to extend with Python. The next step for me is to see if I can extend it to emit HTML documentation of schema.

Related

Use Draw.io to generate SQL / DDL scripts?

There are a lot of resources on internet about how to import tables into ER diagram on Draw.io using sql script.
For example here (but I find plenty of resources googling):
https://desk.draw.io/support/solutions/articles/16000082007-use-the-sql-plugin-to-create-an-entity-relationship-diagram
(SEE PARAGRAPH "Create an ER diagram from SQL code")
I cannot find anything in the reversed direction. Is it possible to create DDL scripts from a ER diagram created through Draw.io?
(plugin? export as xml and import in other tools? anything else...)
I'm dealing with a ER diagram provided by suppliers in Draw.io format. I would like to avoid to handwrite all DDL...
(my case is Oracle 12)
I’ve got a PR in with a plugin that generates sql, DDL script from erdiagram see: https://github.com/jgraph/drawio/pull/3092. So yes it is now possible, if it gets merged in (or rewritten per their closed contribution guidelines) it will then be possible. You can also install the plugin manually (it’s one file).
Example Usage:
You can find the DLL options under arrange > insert
from sql or to sql buttons.
To SQL preview:
Reviewing this my old post I'd like to update that I did not find anything.
So the answer is NO. It's not possible to create DDL from design using Draw.IO
Suppliers were told to begin to learn and work free SQL Data Modeler inside Oracle Sql Developer. It's perfect because diagrams generated with this tool can be used to compare diagram generate from db, creating differences and incremental scripts.

Generate db diagram from any sql statement

I'm using DBArtisan 8.5.5 and it has the ability to generate Database Diagrams using Build Query, it has a nice feature that lets it autojoin, detecting potential relationships on newly added tables to the diagram. So the diagram results into a SQL statement since its a Query Builder after all.
Is it possible to provide an SQL statement in DBArtisan and generate the Database Diagram? In other words, the reverse (give it the SQL to generate the diagram, instead of using diagrams to generate SQL)?
If no such feature, is there a product out there for Sybase DB that will provide said feature?
DbVis is an actionable choice, being open source and powerful - it's got a good amount of extra features aside from the one you need.
If you're willing to pay, Aqua Data Studio is a very complete and intuitive database IDE.
As a middle ground solution, disposing of both a - constantly updated - open source edition, the DBeaver Open Source IDE, and an Enterprise Edition. Both of these also offer what you need, the main differences as of now being interface, SSH algorithm support and SQL debugging framework offered in Enterprise. You can take a deeper look yourself, comparing the Open Source features with the Enterprise ones.

Need tool for graphical projecting database which has option to generate CREATE scripts for different databases

Can someone suggests me tool for graphical projecting database which has option to generate CREATE scripts for different databases ?
Take a look at Oracle SQL Developer Data Modeler. (It is free, too.)

Normalization of an existing SQL database

I have a single-table database I inherited and migrated to SQL Server, and then I normalized it by creating, linking, and filling a whole bunch of lookup-type tables that represented items in the main table. I now want to replace those items in the original table with their foreign keys. Am I stuck writing a bunch of queries or UDF's and then a giant INSERT statement to accomplish this, or is there a tool I can use to point at the various fields and have it handle the grunt work for me?
Redgate SQL Refactor comes with a 14 day evaluation period and has a "Split Table" refactoring which sounds like it might do what you need?
The feature is described thus:
Split Table splits a table into two
tables, and automatically rewrites the
referencing stored procedures, views,
and so on. You can also use this
refactoring to introduce referential
integrity tables. You can select this
feature from the context menu in
Management Studio’s Object Explorer.
I have had similar experiences. I once inherited a fairly large database that required serious overhaul to the schema before I would look at it without scorn.
Because the upgrade was fairly significant, I designed an SSIS package to migrate data from the old schema to the new. Lookup activities were helpful to map old text values to the new keys. I kept a script of my old schema and data handy and would repeatedly restore the database in a sandbox and re-migrate until I could satisfy the powers-that-be that the migration was reliable.
I found there was only a moderate learning curve to getting started with SSIS. If the tool is available to you, I recommend giving it a try.

Defining table structure for a database?

Up until now, my experience with databases has always been working with an intermediate definition layer that we have where I work. i.e. SQL wasn't directly written for the table definitions, but generated from an intermediate file which wrote out SQL scripts for creating the appropriate tables, upgrade scripts between schema changes, and helper functions for doing simple queries/updates/inserts/deletes from the database.
Now I'm in a situation where I don't have access to that, for reasons I won't get into, and I find myself somewhat lost at sea regarding what to do. I need to have a small number of tables in a database, and I'm unsure what's usually done to manage the table definitions.
Do people normally just use the SQL script that does the table creation as their definition, or does everyone just use an IDE that manages the definition in a separate file and regenerates the SQL script to create the tables?
I'd really prefer not to have to introduce a dependence on a specific IDE, because as we all know, developers are whiners that are prone to religious debates over small things.
Open your favorite text editor -> Start writing CREATE scripts -> Save -> Put in Source Control
That script now becomes the basis for you database. Anytime there are schema changes, they get put back into the scripts so that they don't get lost.
These become your definition.
I find it more reliable than depending on any specific IDE/Platform generating those scripts for you.
We write the scripts ourselves and store them in source control like any other code. Then the scripts that are appropriate for a particular version are all groupd together and promoted to prod together. Make sure to use alter table when changing existing tables becasue you don't want to drop and recreate them if they have data! I use a drop and recireate for all other objects though. If you need to add records to a particular table (usually a lookup of sometype) we do that in scripts as well. Then that too gets promoted with the rest of the version code.
For me, putting the scripts in source control however they are generated is the key step. This is how you know what you have changed for the next release. This is how you can see earlier versions and revert back easily if there is a problem. Treat database code the same wayyou treat all other code.
YOu could use one of the data modelling tools that creates scripts for you if you are starting out on a database design and the eventually want to create it for you. Some tools for that are Erwin, Fabforce etc... (though not free)
If you have access to an IDE like SQL Management studio, you can create them by using an GUI thats pretty simple.
If you are writing your own code, Its always better to write your own scripts based on a good template so that you cover all the properties of the definition of the table like the file_group, Collation & stuff. Hope this helps
Once you do create a base copy generate scripts and have a base reference copy of it so that you could do "incremental" changes on them and manage them in a source control.
Though I use TOAD for Oracle, I always write the scripts to create my database objects by hand. It gives you (and your DBA's) more control and knowledge of what's being created and how.
If your schema is too difficult to describe in SQL, you probably have other issues more pressing than which IDE. Use modelling documentation if you need a graphical representation, but yeah, you don't need an IDE.
There are multiple ways out there for what you are asking.
Old traditional way is to have a script file ready with your application that has CREATE TABLE statement.
If you are a developer, and that too a Java enterprise developer, you could generate complete schema using a persistence library called Hibernate. Here is a how to
If you are a DBA level user, you could take schema export from one environment and import that in to your current environment. This is a standard practice among DBAs. But it requires admin access as you can see. Also, the methods are dependent on the database you are using (oracle, db2 etc)