您的位置:首页 > 产品设计 > UI/UE

Change Column Name or Set Default Value in MySql

2016-05-24 16:11 537 查看
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]>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  mysql