Sign in to follow this  
Followers 0
j.silver

Timestamp Default Data

3 posts in this topic

Dear all,

 

For an e.commerce project, I have the following for a carts table, which seem to be the practice in assigning date/time to such table:

 

`date_created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
`date_modified` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',

 

What are the merits in assigning default values as such for each date?

Share this post


Link to post
Share on other sites

Starting date_modified at zero can indicate that the item has never been modified before.

 

date_created has to be set as soon as the row is created.

Share this post


Link to post
Share on other sites

You have to use a default value if you define the column as not null, but don't include those columns in the insert statement. You can allow null values in a column and then if you don't include them in the insert they will default to null. date_modified would make more sense to default to a null value instead of a point 2016 years ago.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0