MySQL使用日期列作为UNIQUE索引
https://dev.mysql.com/doc/refman/8.0/en/date-and-time-functions.html#function_extract
https://dev.mysql.com/doc/refman/8.0/en/date-and-time-functions.html#function_date-format
https://dev.mysql.com/doc/refman/8.0/en/create-table-generated-columns.html
https://dev.mysql.com/doc/refman/8.0/en/date-and-time-functions.html#function_get-format
只能使用自动生成列,将DATETIME类型转为VARCHAR类型,然后根据 column(length) 进行加索引,可根据一定的时间规则防止用户重复点击
无法使用DATETIME类型指定长度的情况下进行加索引,所以只能转为varchar类型
`gen_create_datetime` varchar(14) CHARACTER SET utf8 COLLATE utf8_bin GENERATED ALWAYS AS (date_format(`create_time`,get_format(DATETIME, _utf8mb4'INTERNAL'))) STORED
UNIQUE KEY `organ_id` (`organ_id`,`gen_create_datetime`(12),`del_flag`) USING BTREE
复制请注明出处,在世界中挣扎的灰太狼