如何在下表中更新字段“aaj”并更改日期?

gstyhher  于 2021-07-26  发布在  Java
关注(0)|答案(1)|浏览(341)
CREATE TABLE `aaj` (
  `ID` int(10) NOT NULL,
  `aaj` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `mahina` varchar(6) GENERATED ALWAYS AS (convert(date_format(`aaj`,'%y/%m') using utf8mb4)) STORED NOT NULL,
  `saptaah` varchar(7) GENERATED ALWAYS AS (convert(date_format(`aaj`,'%x/%v') using utf8mb4)) STORED NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
tpgth1q7

tpgth1q71#

我想你想 ON UPDATE CURRENT_TIMESTAMP :

CREATE TABLE `aaj` (
  `ID` int(10) NOT NULL,
  `aaj` timestamp NOT NULL 
       DEFAULT CURRENT_TIMESTAMP
       ON UPDATE CURRENT_TIMESTAMP,
  `mahina` varchar(6) GENERATED ALWAYS 
      AS (convert(date_format(`aaj`,'%y/%m') using utf8mb4)) STORED NOT NULL,
  `saptaah` varchar(7) GENERATED ALWAYS 
       AS (convert(date_format(`aaj`,'%x/%v') using utf8mb4)) STORED NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

旁注:通常使用与表同名的列(这里, aaj ):从数据库的Angular 来看,这不是一个问题,但它往往会让人感到困惑。

相关问题