SQL Tips & Database Tools

Actionable SQL tips, database tools, and workflow tricks for developers, DBAs, and data engineers.

List of posts View on GitHub

How To: Create a MySQL Database Diagram Using a Sketch Image

Often we make some sketches of the database we plan to create on a blackboard or a sheet of paper before we actually design its structure on computer. After that we discuss the entities we’ve got, normalize them and repeat these actions several times. As a result we get a completely approved database structure in the form of an image file in the project documentation.

Question: How to create a database diagram basing on the image available?

Let’s try to do this using Database Designer of dbForge Studio for MySQL.

Let us suppose that you have a sketch of the future database:

Database Structure

Database Structure

To place this picture onto an empty diagram you should create an empty document, for example, Diagram1.dbd by pressing New Database Diagram on the Standard toolbar. After that you should press the New Image button on the Database Diagram toolbar. The mouse pointer will change to an icon with a picture. Click on any part of the diagram. In the Open dialog window that appeared select the image with the diagram structure sketch.

Open New Image

Database Designer: Open New Image

Now as you see the database sketch you can recreate the database from it. Let’s create the necessary tables with Primary Key and indexes one by one. For example, to create the Sessions table press the New Table button on the Database Diagram toolbar. The mouse pointer should change to an icon with a table. Click on any part of the diagram. A window for editing the Table1 table should appear.

Create New Table

Database Designer: Create New Table

Using the database editor window you should do the following:

As a result we’ve got a new entity on the diagram – the Sessions table.

Design New Table

Database Designer: Design New Table

Move the table on the diagram not far from its presentation on the sketch. Then create the next table, for example, Hits, in the same way and move it not far from its presentation on the sketch.
Now we can add a relation between the Hits and Sessions tables. To do this, you should:

Create New Relation

Database Designer: Create New Relation

As a result, we’ve bound two tables – “Hits” and “Sessions” using the foreign key “hits_FK”.

Display Relation

Database Designer: Display Relation

Now we should repeat the same operations as creating and designing tables, creating indexes and relations between tables.
An important part of the database design process is logical division of database objects into groups. Database Designer available in dbForge Studio for MySQL has a special Container component for this purpose.
To create a new container and move the necessary objects into it you should:

New Container

Database Designer: New Container

And the final step in the process of database creation using a sketch is the optimization of database objects location on the diagram. The algorithm used by Layout Diagram is designed so that the program redraws the relations between tables so that they would not intersect each other. This allows to save space on the diagram and makes it readable.

Layout Diagram

Database Designer: Layout Diagram

As a result of the actions described above we’ve created a database using a sketch without switching over to other applications displaying the image of the diagram using Alt+Tab or printing the sketch owing to the unique functionality of dbForge Studio for MySQL.

(*) On the diagram, columns with the Not Null property enabled are displayed in bold (for example, the HitDate column of the SpiderHits table) unlike other columns (for example, the HitUrl column of the SpiderHits table).
(**) To create Foreign Key between tables both these tables should have been created with Engine=InnoDB.

You can download a free 30-day evaluation of dbForge Studio for MySQL.

tags: database diagram, MySQL, dbForge Studio for MySQL