- 时间字段:
`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"]}