MariaDB列数据类型DATE已转换为DATETIME数据类型

omqzjyyz  于 2023-03-08  发布在  其他
关注(0)|答案(1)|浏览(126)

当我尝试添加一个新的日期数据类型列到我的表,它会自动转换(见所附的屏幕截图)为DATETIME数据类型,有什么SQL设置我必须禁用,以防止这种情况?
MariaDB版本为10.6.11。

MariaDB [mydb]> describe my_table;
+-------+---------+------+-----+---------+-------+
| Field | Type    | Null | Key | Default | Extra |
+-------+---------+------+-----+---------+-------+
| id    | int(11) | YES  |     | NULL    |       |
+-------+---------+------+-----+---------+-------+
1 row in set (0.001 sec)

MariaDB [mydb]> ALTER TABLE my_table ADD my_date DATE;
Query OK, 0 rows affected (0.010 sec)
Records: 0  Duplicates: 0  Warnings: 0

MariaDB [mydb]> describe my_table;
+---------+----------+------+-----+---------+-------+
| Field   | Type     | Null | Key | Default | Extra |
+---------+----------+------+-----+---------+-------+
| id      | int(11)  | YES  |     | NULL    |       |
| my_date | datetime | YES  |     | NULL    |       |
+---------+----------+------+-----+---------+-------+
2 rows in set (0.002 sec)

MariaDB [mydb]> show create table my_table;
+----------+--------------------------------------------------------------------------------------------+
| Table    | Create Table                                                                               |
+----------+--------------------------------------------------------------------------------------------+
| my_table | CREATE TABLE "my_table" (
  "id" int(11) DEFAULT NULL,
  "my_date" datetime DEFAULT NULL
) |
+----------+--------------------------------------------------------------------------------------------+
1 row in set (0.000 sec)

MariaDB [mydb]> select @@sql_mode;
+------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| @@sql_mode                                                                                                                                                       |
+------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| PIPES_AS_CONCAT,ANSI_QUOTES,IGNORE_SPACE,ORACLE,NO_KEY_OPTIONS,NO_TABLE_OPTIONS,NO_FIELD_OPTIONS,STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,SIMULTANEOUS_ASSIGNMENT |
+------------------------------------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.000 sec)
knsnq2tg

knsnq2tg1#

这是由ORACLE SQL模式造成的;在您更改表时临时删除它:

set session sql_mode=replace(@@sql_mode,'ORACLE','');
alter table ...

fiddle

相关问题