Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Date / Timestamp to record when a record was added to the table? [duplicate]

Does anyone know of a function as such that I can use to add an automatic date and timestamp in a column for when a user adds a record to the database table?

like image 911
Betty Avatar asked May 23 '12 13:05

Betty


People also ask

How do I create a date timestamp in Access?

In the Navigation Pane, double-click the table to which you want to add the time stamp field. Access opens the table in Datasheet view. In the first blank column labeled Click to Add, select Date & Time from the drop-down list of data types. Access creates a new field and then displays a temporary field name.


1 Answers

You can create a non-nullable DATETIME column on your table, and create a DEFAULT constraint on it to auto populate when a row is added.

e.g.

CREATE TABLE Example ( SomeField INTEGER, DateCreated DATETIME NOT NULL DEFAULT(GETDATE()) ) 
like image 140
AdaTheDev Avatar answered Sep 30 '22 06:09

AdaTheDev