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 自动更新的方法,没有找到,经自己尝试用上面方法可以修改。

  • 相关阅读:
    Python中xlrd和xlwt模块使用方法
    python正则表达式中含有变量的写法
    python中取整的几种方法
    python request 获取cookies value值的方法
    MySQL数据库初识
    三次登录验证以及购物车
    常用设计模式学习
    test0805
    生成器和各种推导式
    第一类对象 闭包 迭代器
  • 原文地址:https://www.cnblogs.com/mfrbuaa/p/4166760.html
Copyright © 2011-2022 走看看