Database diagram with dbdiagram.io

Database diagram with dbdiagram.io

ยท

4 min read

Creating database diagrams before an actual database implementation is quite important because it reduces the time spent during implementation, it provides a blueprint for the developer to follow during implementation.

WHAT IS A DATABASE DIAGRAM?

A database diagram is a graphical representation of the structure of a database and the relationship between database objects. Database diagrams help you visualize the relationship between the tables on your database therefore giving you a clearer picture of what you want to implement, Most times developers spend time restructuring their database because they never actually went through the database design phase, take for example a UI/UX designer who has to keep iterating until he/she is able to perfect the features for the product he/she is working to excel, so also do developers have to prioritize database schema designs.

GETTING STARTED WITH DBDIAGRAM.IO

  1. Visit dbdiagram.io
  2. Click on the CREATE YOUR DIAGRAM button
  3. Navigate to screen that has the appearance of a code editor(left-hand side).
  4. You can go through the already written structure to get a better overview before clearing the editor's screen.

CREATING YOUR FIRST DATABASE TABLE

  1. Go to the cleared editor and type in
    table table's name{
    }
    , This tells dbdiagram.io that you and creating a table with the specified name
  2. Within the curly braces type in the columns required for your database alongside the column's data type and metadata.
    Table user{
    Id int [pk, not null, increments]
    Username string[unique]
    Email string[unique]
    Password string [not null]
    Address string[null]
    }
    ,The data placed within the square bracket gives more information about the given field. For example:
    Pk means that the ID field is a primary key, A primary key is unique means of identification when we talk about database it's the data under a specific column that is unique, doesn't change and is not null, this means that that column cannot be empty for any given entity on your database. Not null signifies that this column cannot be empty. Null signifies that that column can be left empty(null) for a given entity. Unique signifies that the data under that column must be unique within a given database.

    RELATIONSHIPS WITHIN A DATABASE.

    Relationships within the database world means connection between two or more tables. The following are some of the relationship type you can find while talking about databases:
  3. < One-To-Many
  4. > Many-To-One
  5. - One-To-One
    One-To-Many One to many simply means that an entity on one table is connected to different entities on a different table. For example: A student from a table named student can be associated with different courses from the courses table but a single course cannot be connected to one student.,Imagine having a course created specifically for you to study in school ๐Ÿ˜‚?.
    Many-To-One The only difference between the Many-To-One and the One-To-Many relationship is that for the Many-To-One relationship many entities from the parent table are connected to a single entity on the child table while for the One-To-Many an entity on the parent table is connected to two or more entities on the child table, what do I mean by parent table?. A parent table can be seen as a universal table, the table that births the child table, basically without the parent table the child table wouldn't exist. Without creating a student or a teachers table the creation of the subjects table wouldn't be important, so the teachers/students table births the subjects table.
    One-To-One A single element on the parent table is connected to a single element on the child table.
    CREATING RELATIONSHIPS BETWEEN TABLES USING DBDIAGRAM.IO
    the following are the steps to follow in creating relationships between tables using dbdiagram.io:
  6. Long-syntax Ref name-optional { table1.field1 < table2.field2 }

  7. Short-syntax Ref name-optional: table1.field < table2.field2

Example Table students{
Id int [pk, increments]
name string [not null]
}
Table deparment{
Id int[pk, increments]
studentId string[unique, not null]
}
Ref students.name -department.studentId
This reads one name on the students table to one studentId on the department table
I hope this article was helpful to you?, Thanks for reading.

ย