In this blog’s exmple, two scenes are included:
- Change column’s name
- Set default value to the specified column
Example:
MariaDB [testdate]> DESCRIBE ttt;
+--------------+-------------+------+-----+-------------------+-------+
| Field | Type | Null | Key | Default | Extra |
+--------------+-------------+------+-----+-------------------+-------+
| others | varchar(20) | YES | | NULL | |
| the_datetime | datetime | NO | | CURRENT_TIMESTAMP | |
+--------------+-------------+------+-----+-------------------+-------+
2 rows in set (0.00 sec)
MariaDB [testdate]> ALTER TABLE ttt CHANGE the_datetime the_datetime2 DATETIME;
Query OK, 0 rows affected (0.42 sec)
Records: 0 Duplicates: 0 Warnings: 0
MariaDB [testdate]> DESCRIBE ttt;
+---------------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+---------------+-------------+------+-----+---------+-------+
| others | varchar(20) | YES | | NULL | |
| the_datetime2 | datetime | YES | | NULL | |
+---------------+-------------+------+-----+---------+-------+
2 rows in set (0.00 sec)
MariaDB [testdate]> ALTER TABLE ttt MODIFY the_datetime2 DATETIME DEFAULT CURRENT_TIMESTAMP;
Query OK, 0 rows affected (0.00 sec)
Records: 0 Duplicates: 0 Warnings: 0
MariaDB [testdate]> DESCRIBE ttt;
+---------------+-------------+------+-----+-------------------+-------+
| Field | Type | Null | Key | Default | Extra |
+---------------+-------------+------+-----+-------------------+-------+
| others | varchar(20) | YES | | NULL | |
| the_datetime2 | datetime | YES | | CURRENT_TIMESTAMP | |
+---------------+-------------+------+-----+-------------------+-------+
2 rows in set (0.00 sec)
MariaDB [testdate]>