DEV Community

Cover image for Creating tables & generating code in ChartDB
Ankur Singh
Ankur Singh

Posted on • Edited on

Creating tables & generating code in ChartDB

Introduction

Welcome 👋 to this blog. Are you working with databases with complex schema and you are stuck in visualizing the entire database in one view so that your task will be easier then we got you covered!!! We are introducing ChartDB to visualize your DB which is a Free and open-source, database design editor. Open source & no login required, yep you heard it correctly. You can also generate the scheme code for complex tables.

SQL Tables

Suppose we in our organization work in a database containing the stores' data. In this scenario we have three tables named Product, Store & Customer.
The schema of these tables is as follows:

Store
-----
store_id       INT          PRIMARY KEY
area_sq        DECIMAL(10,2)
city           VARCHAR(100)
province       VARCHAR(100)


Product
-------
product_id     INT          PRIMARY KEY
store          INT          FOREIGN KEY REFERENCES Store(store_id) ON DELETE CASCADE
price          DECIMAL(10,2)
description    TEXT
name           VARCHAR(100)


Customer
--------
customer_id    INT          PRIMARY KEY
product        INT          FOREIGN KEY REFERENCES Product(product_id) ON DELETE SET NULL
store          INT          FOREIGN KEY REFERENCES Store(store_id) ON DELETE SET NULL
name           VARCHAR(100)
age            INT

Enter fullscreen mode Exit fullscreen mode

But in this case, we have only three tables but it can vary based on the complexity of the projects we are working on. We can have a good number of tables as well. So we can understand that visualizing this many tables can be a nightmare. But using ChartDB we can easily visualize the tables.

Using ChartDB to visualize the tables

First thing first, visit the ChartDB app link here. Then you can see this type of UI:

ChartDB UI

Then we will create the first table named Store

  1. First click on Add Table
    Add table

  2. Change the name of the table and add the attributes
    Add table and attributes

Our table will look like something like that:

First table

Some features of chartDB are as follows:

  • Variety of data type

Variety of data type

  • Adding indexes to the tables

Adding indexes

  • Adding comments in the tables

Adding comments

Here we go

3-tables

Here we have all the three tables, now the only thing remaining is to create the relation between them:

Adding the realations

This is the completed version of the visualization of the tables with their relation as well.

Completed visulalization

Save the image

Saving the visualization image

You can also generate the code as well.

Image description

Image description

🎉 You nailed it

You have now learned how to use ChartDB in personal as well as for the business purpose.

Thank you for reading! If you enjoyed this content, feel free to connect to me:
📧 Email: ankursingh91002@gmail.com

🔗 LinkedIn: Ankur Singh

🔗 Twitter: @ankur_136

Let's connect and create something great together!

Top comments (0)