DEV Community

Cover image for How To Design a MySQL Database for your Basic Notification System?

How To Design a MySQL Database for your Basic Notification System?

Nik L. on January 11, 2024

TL;DR: Check out a tabular comparison here: MySQL vs Cassandra vs Elastic Search vs Redis vs Amazon Aurora vs Google cloud spanner Managing use...
Collapse
 
prsaya profile image
Prasad Saya • Edited

The createdAt and updatedAt columns can be:

createdAt DATETIME 
  NOT NULL DEFAULT (CURRENT_TIMESTAMP()),
updatedAt DATETIME 
  NOT NULL DEFAULT (CURRENT_TIMESTAMP()),
Enter fullscreen mode Exit fullscreen mode

[ EDIT: corrected to CURRENT_TIMESTAMP() from CURDATE()]
instead of

`createdAt` DATETIME 
  NOT NULL,
`updatedAt` DATETIME 
  NULL DEFAULT NULL,
Enter fullscreen mode Exit fullscreen mode

Setting default values for date (date and time) fields in a database is often used, especially in the case of created and updated timestamps. As such TIMESTAMP type is also acceptable instead of DATETIME type.