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:
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中的integer 数据类型
- MySQL存储过程
- mysql中int、bigint、smallint 和 tinyint的区别与长度
- mysql load data 导出、导入 csv
- source命令执行SQL脚本文件
- MySQL创建用户及权限控制
- MySQL管理数据表
- linux下mysql添加用户
- mysql procedure
- mysql触发器
- MySQL 备份和恢复策略
- mac下安装mysql(转载)
- mysql 修改编码 Linux/Mac/Unix/通用(杜绝修改后无法启动的情况!)
- MySQL数据的导出、导入(mysql内部命令:mysqldump、mysql)
- mysql数据行转列
- Linux下修改MySQL编码的方法
- MySQL Server 日志
- MySQL 安全事宜
- MySQL 备份与恢复