Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MySql TIMESTAMP column is auto updated. Why?

Tags:

php

mysql

I have a table created with this SQL:

CREATE TABLE `test_table` (
  `id` BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
  `data` TEXT,
  `timestamp` TIMESTAMP
) CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE InnoDB;

But when I run SHOW CREATE TABLE test_table, I get:

CREATE TABLE `test_table` (
 `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
 `data` text COLLATE utf8_unicode_ci,
 `timestamp` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
 PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci

Why the timestamp column being assigned ON UPDATE CURRENT_TIMESTAMP by default? I do not know how to get rid of this. Any help would be greatly appreciated.

like image 630
VPZ Avatar asked Dec 18 '15 12:12

VPZ


1 Answers

If you want that to your timestamp will be not added automatically ON UPDATE you have to define it like this

CREATE TABLE `test_table` (
   ...
   `timestamp` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP
) ...
like image 185
Armen Avatar answered Sep 30 '22 04:09

Armen