I am creating a new table, and I would like each row to have a column equal to the time the row is inserted into the table. Is there a way to do this in the create table statement, or do I need to do this in my insert statement?
This should work:
CREATE TABLE table1 ( timeStampColumn TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP );
Something like this when creating a table.
CREATE TABLE t1 ( insert_timestamp TIMESTAMP DEFAULT CURRENT_TIMESTAMP );
The TIMESTAMP data type offers automatic initialization and updating to the current date and time (that is, the current timestamp). MORE
TIMESTAMP
Example
CREATE TABLE t1 ( ts TIMESTAMP );
you can set the default value as NOW as
CREATE TABLE example ( id INT NOT NULL PRIMARY KEY AUTO_INCREMENT, data VARCHAR(140), created TIMESTAMP DEFAULT NOW() );
SQLFiddle demo
Automatic initialization and update for TIMESTAMP and DATETIME
CREATE TABLE t1 ( id int, update_date TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP );
Source: https://habr.com/ru/post/1491877/More articles:Apple Push notification restrictions - iossed replaces 2 different templates in conf - bashConverted PHP code to (My) SQL stored procedure - phpuninitialized enum variable - c ++A simple Moq example - connecting to a database and processing files - c #ASP.NET MVC Embedded Package - optimizationReading data from Tenma 72-7732 multimeter using PyUSB - pythonAndroid ViewAnimator height changes base on child - javaSlow MySQL queries in Python, but fast elsewhere - pythonChanging additional store options before a grid sorting event - extjsAll Articles