设为首页 加入收藏

TOP

MySQL之修改表中的列(二)
2015-11-21 01:54:59 来源: 作者: 【 】 浏览:1
Tags:MySQL 修改
-----+-----+------------+----------------+ 4 rows in set (0.01 sec) mysql> #如果想增加一列,并位于表的最前面,用first mysql> alter table m1 add pid int not null default '' first; ERROR 1067 (42000): Invalid default value for 'pid' mysql> alter table m1 add pid int not null first; Query OK, 0 rows affected (0.40 sec) Records: 0 Duplicates: 0 Warnings: 0 mysql> desc m1; +----------+------------------+------+-----+------------+----------------+ | Field | Type | Null | Key | Default | Extra | +----------+------------------+------+-----+------------+----------------+ | pid | int(11) | NO | | NULL | | | id | int(10) unsigned | NO | PRI | NULL | auto_increment | | username | char(20) | NO | | | | | gender | char(1) | NO | | | | | birth | date | NO | | 0000-00-00 | | +----------+------------------+------+-----+------------+----------------+ 5 rows in set (0.01 sec) mysql> #删除列 mysql> desc m1; +----------+------------------+------+-----+------------+----------------+ | Field | Type | Null | Key | Default | Extra | +----------+------------------+------+-----+------------+----------------+ | pid | int(11) | NO | | NULL | | | id | int(10) unsigned | NO | PRI | NULL | auto_increment | | username | char(20) | NO | | | | | gender | char(1) | NO | | | | | birth | date | NO | | 0000-00-00 | | +----------+------------------+------+-----+------------+----------------+ 5 rows in set (0.01 sec) mysql> alter table m1 drop pid; Query OK, 0 rows affected (0.37 sec) Records: 0 Duplicates: 0 Warnings: 0 mysql> desc m1; +----------+------------------+------+-----+------------+----------------+ | Field | Type | Null | Key | Default | Extra | +----------+------------------+------+-----+------------+----------------+ | id | int(10) unsigned | NO | PRI | NULL | auto_increment | | username | char(20) | NO | | | | | gender | char(1) | NO | | | | | birth | date | NO | | 0000-00-00 | | +----------+------------------+------+-----+------------+----------------+ 4 rows in set (0.01 sec) mysql> alter table m1 modify gender char(4) not null default ''; Query OK, 0 rows affected (0.47 sec) Records: 0 Duplicates: 0 Warnings: 0 mysql> desc m1; +----------+------------------+------+-----+------------+----------------+ | Field | Type | Null | Key | Default | Extra | +----------+------------------+------+-----+------------+----------------+ | id | int(10) unsigned | NO | PRI | NULL | auto_increment | | username | char(20) | NO | | | | | gender | char(4) | NO | | | | | birth | date | NO | | 0000-00-00 | | +----------+------------------+------+-----+------------+----------------+ 4 rows in set (0.05 sec) mysql> alter table m1 change id uid int unsigned; Query OK, 0 rows affected (0.44 sec) Records: 0 Duplicates: 0 Warnings: 0 mysql> desc m1; +----------+------------------+------+-----+------------+-------+ | Field | Type | Null | Key | Default | Extra | +----------+------------------+------+-----+------------+-------+ | uid | int(10) unsigned | NO | PRI | 0 | | | username | char(20) | NO | | | | | gender | char(4) | NO | | | | | birth | date | NO | | 0000-00-00 | | +----------+------------------+------+-----+------------+-------+ 4 rows in set (0.01 sec) mysql> exit; ----------------------------------------------------------------------------------

欢迎探讨与学习。。。。。。

首页 上一页 1 2 下一页 尾页 2/2/2
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇mysql5.6的一些限制 下一篇MySQL BIGINT UNSIGNED valueis o..

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容: