zoukankan      html  css  js  c++  java
  • mysql增加和删除字段

    • 时间字段:
    `create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
    `last_update_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '最后更新时间',
    
    • 删除某个字段:
    ALTER TABLE `tableName` drop COLUMN `columeName`;
    
    • 增加某个字段:
    ALTER TABLE `tableName` ADD COLUMN `columeName` varchar(255) NOT NULL DEFAULT '' COMMENT '备注信息' AFTER `anotherColumeName`;
    
    • 创建表:
    CREATE TABLE `tableName` (
      `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
      `msg` varchar(60) NOT NULL DEFAULT '' COMMENT '备注',
      `create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
      PRIMARY KEY (`id`)
    ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='导出excel';
    
    • 删除数据库
      drop database tableName;

    • 删除表
      drop table 表名;


    MySQL5.7以上版本json字段的处理

    创建表:

    CREATE TABLE `tb_testjson` (
    	`id` BIGINT(20) NOT NULL AUTO_INCREMENT,
    	`content` JSON NULL DEFAULT NULL,
    	PRIMARY KEY (`id`)
    )
    COLLATE='latin1_swedish_ci'
    ENGINE=InnoDB
    AUTO_INCREMENT=0
    ;
    

    1.查询json字段的值

    select content ,JSON_EXTRACT(content,"$.name") as name from tb_testjson;
    
    #select content ,content->"$.name" as name from tb_testjson;
    
    

    2.插入:
    UPDATE tb_testjson SET content=JSON_ARRAY_APPEND(content,'$.name','test') WHERE id = 2;

    {"age": "11", "name": ["ww", "test"]}
    
  • 相关阅读:
    杂题
    [ AtCoder Grand Contest 031] C
    [ AtCoder Regular Contest 107 ] C
    [ 实验舱 CSP/NOIP新赛制内部挑战赛4 ] 树上询问
    [ 2020牛客NOIP赛前集训营-提高组(第六场) ] 补题
    [NOI Online #2 提高组]子序列问题
    洛谷P4317 花神的数论题
    [AHOI2009]同类分布
    洛谷P3413 SAC#1
    数位dp小结
  • 原文地址:https://www.cnblogs.com/mentalidade/p/6293200.html
Copyright © 2011-2022 走看看