mysql中列的增删改

Posted FireC@t @ Perl6

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了mysql中列的增删改相关的知识,希望对你有一定的参考价值。

增加列:
alter table table_name add name varchar(100);
alter table table_name add name varchar(100) after id;
alter table table_name add name varchar(100) first;

修改列名:

alter table table_name change name name varchar(10);
#change可改名字与字段类型
mysql> alter table a change uid uid int;
Query OK, 0 rows affected (0.04 sec)
Records: 0  Duplicates: 0  Warnings: 0

alter table table_name modify name int;
#modify只改字段类型
mysql> desc a;
+-------+---------+------+-----+---------+-------+
| Field | Type    | Null | Key | Default | Extra |
+-------+---------+------+-----+---------+-------+
| namea | char(1) | YES  |     | NULL    |       |
| id    | int(11) | YES  |     | NULL    |       |
| uid   | int(11) | YES  |     | NULL    |       |
+-------+---------+------+-----+---------+-------+
3 rows in set (0.01 sec)

mysql>
mysql>
mysql> alter table a modify uid varchar(1);
Query OK, 0 rows affected (0.07 sec)
Records: 0  Duplicates: 0  Warnings: 0

mysql> desc a;
+-------+------------+------+-----+---------+-------+
| Field | Type       | Null | Key | Default | Extra |
+-------+------------+------+-----+---------+-------+
| namea | char(1)    | YES  |     | NULL    |       |
| id    | int(11)    | YES  |     | NULL    |       |
| uid   | varchar(1) | YES  |     | NULL    |       |
+-------+------------+------+-----+---------+-------+
3 rows in set (0.01 sec)

mysql>

删除列:
alter table table_name drop column_name;


#手册
help modify;

 

以上是关于mysql中列的增删改的主要内容,如果未能解决你的问题,请参考以下文章

Oracle数据库的增删改,索引视图以及序列的创建和销毁

MySQL: 表的增删改查(进阶1)

MySQL表的增删改查(进阶)

mySQL CRUD操作(数据库的增删改查)

mysql 的增删改查 实现代码

基本sql语句--列的增删改