Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Message notification app database structure design

I am developing android notification application. I have doubt in my database structure.

When one user sends notification to other user, I am inserting single row in my database table (Notification) and when one user send same Notification text to multiple user, I am inserting multiple rows in table.

Is it right approach to create multiple rows for different users?enter image description here

like image 741
Nimish Patel Avatar asked Dec 27 '25 16:12

Nimish Patel


1 Answers

Is it right approach to create multiple rows for different users?

You are very right in having doubts about this approach. Back when there were no relational databases, there sometimes was no other way. If you use your database schema with multiple rows then you will end up storing (and also processing) some values more often than needed. Relational databases were invented to avoid redundancy, because redundancy is expensive in terms of storage, performance and maintenance time.

In your table Notification the only column which will not be stored more than once is ToUserId.

So I think you're better off with your table Notification minus the ToUserId column. This piece of information could go into a new table with two data columns: NotificationId (as ForeignKey pointing to the notification info) and ToUserId (pointing to the user data).

like image 80
Bö macht Blau Avatar answered Dec 30 '25 05:12

Bö macht Blau