zoukankan      html  css  js  c++  java
  • mysql 添加[取消]timestamp的自动更新

    创建自动更新的 timestamp (插入或修改时 uptime都会自动更新)

    CREATE TABLE `hello` (
    `id` int(11) NOT NULL,
    `uptime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
    KEY `line_id` (`id`)
    ) ENGINE=MyISAM AUTO_INCREMENT=3526391 DEFAULT CHARSET=utf8

    修改为不自动更新(只是插入是自动生成当前时间)

    alter table hello change uptime uptime timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP;

    show create table hello;

    CREATE TABLE `hello` (
    `id` int(11) NOT NULL,
    `uptime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
    KEY `line_id` (`id`)
    ) ENGINE=MyISAM AUTO_INCREMENT=3526391 DEFAULT CHARSET=utf8

    再修改为自动更新:

    alter table hello change uptime uptime timestamp 

    show create table hello;

    CREATE TABLE `hello` (
    `id` int(11) NOT NULL,
    `uptime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
    KEY `line_id` (`id`)
    ) ENGINE=MyISAM AUTO_INCREMENT=3526391 DEFAULT CHARSET=utf8

    mysql 有修改默认值的方法

    alter table table_name alter column column_name set default xxx;

    此方法适用于一般类型的字段,却无法修改timestamp ,修改时总是报错,网上搜索关于修改timestamp 自动更新的方法,没有找到,经自己尝试用上面方法可以修改。

  • 相关阅读:
    leetcode 6 ZigZag Conversion
    OpenCL异构计算资料收集
    leetcode 21 Merge Two Sorted Lists
    leetcode 226 Invert Binary Tree 翻转二叉树
    leetcode 8 String to Integer (atoi)
    leetcode 27 Remove Element
    【Office】add ins
    【office】deploy
    【Office】add ins manifest
    【设计】交互设计理念
  • 原文地址:https://www.cnblogs.com/mfryf/p/4167233.html
Copyright © 2011-2022 走看看