Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I alter a timestamp to set by default to the current time?

Tags:

mysql

The code below doesn't seem to work even though the collumn and table does exist, any ideas?

ALTER TABLE `table` CHANGE 'collumn_1' 'collumn_1' TIMESTAMP DEFAULT 'CURRENT_TIMESTAMP' NOT NULL

I'm just trying to make the collumn available so it can store the current date and time when any data is added to this table.

like image 791
david99world Avatar asked Mar 31 '11 14:03

david99world


People also ask

How do I add a default value to a TIMESTAMP column?

Use of DEFAULT CURRENT_TIMESTAMP and ON UPDATE CURRENT_TIMESTAMP is specific to TIMESTAMP. The DEFAULT clause also can be used to specify a constant (nonautomatic) default value; for example, DEFAULT 0 or DEFAULT '2000-01-01 00:00:00'.

What is the default value for TIMESTAMP?

A TIMESTAMP column that permits NULL values does not take on the current timestamp at insert time except under one of the following conditions: Its default value is defined as CURRENT_TIMESTAMP and no value is specified for the column.

How do you change the TIMESTAMP?

Syntax – Update value to Current TimestampALTER TABLE table_name updates table schema. CHANGE column_name updates the column to. column_name TIMESTAMP NOT NULL defines the column as of datatype TIMESTAMP. DEFAULT CURRENT_TIMESTAMP sets the default value of the column to CURRENT_TIMESTAMP.

What is the default value for TIMESTAMP in Oracle?

TIMESTAMP has a default of 0 unless defined with the NULL attribute, in which case the default is NULL .


1 Answers

ALTER TABLE `table` MODIFY collumn_1 TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL;
like image 136
Quassnoi Avatar answered Sep 18 '22 16:09

Quassnoi