Er diagram explained

Rajan Lagah
3 min readFeb 18, 2021

--

I have created a small CRUD app and for that this is DB design ( ER diagram ).

Entity

Entity is just a table that got created in relational database. In this app we have 3 Tables which i will explain later

Attributes

Attributes are the column names of table/entity. Now in Updoot table we have lot of attributes and one of it is voteStatus

Relation

This is simple one word verb that will tell the relation between 2 tables/entities

Primary key

Primary key is column that have unique non null values. It represent each entry in row hence also called unique identifier.

Cardinality of Relationships

It represent number of entries in one table can map/relate to number of entries in other table

User table

We can see that User table have

  • id = Primary key
  • updatedAt = Time when user update/create username/password
  • username = username of user
  • password = password of user
  • createdAt = Time when user is created

Points to think

  • Normalisation

We could have many to many relationship b/w User and Post as

  1. User can have many post
  2. Post can have users who up-voted them

But this is not a great way to design DB. In DB design 1 step is to remove Many to Many relationships. You will do them using normalisation. So that will help you to remove redundancy.

  • You should save hashed password in DB so that in case your DB got hacked hacker wont know the password.

--

--