Вот моя таблица DDL:
-- auto-generated definition
create table treehole
(
id bigint auto_increment
primary key,
content text not null,
author_id bigint not null,
create_time timestamp default CURRENT_TIMESTAMP not null,
modify_time timestamp not null,
oo_num int default 0 not null,
xx_num int default 0 not null
);
create index Treehole_author_id_index
on treehole (author_id);
create index Treehole_create_time_index
on treehole (create_time desc);
create index Treehole_oo_num_index
on treehole (oo_num desc);
И я хочу установить значение по умолчанию дляmodify_time как current_timestamp:
alter table `treehole`
alter column `modify_time`
set default current_timestamp;
А бывает:
[42000][1064] You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'current_timestamp' at line 3
Моя версия MySQL 8.0.422.
Ваш синтаксис отключен, используйте:
ALTER TABLE treehole
MODIFY COLUMN modify_time TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP;
Суть в том, что вам нужно MODIFY COLUMN
, а не ALTER COLUMN
, а также вам нужно в основном переформулировать определение всего столбца, а не просто переформулировать значение по умолчанию.
Упс.. Это работает, но мой SQL создается автоматически с помощью datagrip 😂