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?
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).
上一篇: Laravel多语言网站数据库结构
下一篇: 消息通知应用数据库结构设计