接上篇文章《修改、删除数据库表数据》,修改数据库中表名,表中增加、删除字段。
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
mysql> use gbk #进入gbk数据库 mysql> desc test; +-------+----------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra | +-------+----------+------+-----+---------+----------------+ | id | int(4) | NO | PRI | NULL | auto_increment | | name | char(20) | NO | | NULL | | +-------+----------+------+-----+---------+----------------+ mysql> alter table test add gender char(4); #增加gender mysql> desc test; +--------+----------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra | +--------+----------+------+-----+---------+----------------+ | id | int(4) | NO | PRI | NULL | auto_increment | | name | char(20) | NO | | NULL | | | gender | char(4) | YES | | NULL | | +--------+----------+------+-----+---------+----------------+ mysql> alter table test add age int(4) after name; mysql> desc test; +--------+----------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra | +--------+----------+------+-----+---------+----------------+ | id | int(4) | NO | PRI | NULL | auto_increment | | name | char(20) | NO | | NULL | | | age | int(4) | YES | | NULL | | | gender | char(4) | YES | | NULL | | +--------+----------+------+-----+---------+----------------+ mysql> show tables; +---------------+ | Tables_in_gbk | +---------------+ | test | +---------------+ mysql> rename table test to hello; mysql> show tables; +---------------+ | Tables_in_gbk | +---------------+ | hello | +---------------+ mysql> alter table hello rename to world; mysql> show tables; +---------------+ | Tables_in_gbk | +---------------+ | world | +---------------+ mysql> alter table world drop age; mysql> desc world; +--------+----------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra | +--------+----------+------+-----+---------+----------------+ | id | int(4) | NO | PRI | NULL | auto_increment | | name | char(20) | NO | | NULL | | | gender | char(4) | YES | | NULL | | +--------+----------+------+-----+---------+----------------+ 3 rows in set (0.00 sec) |
申明:本文由BYRD原创(基于Mysql5.6.16),未经许可禁止转载! SourceByrd's Weblog-https://note.t4x.org/database/table-increase-rename/
申明:除非注明Byrd's Blog内容均为原创,未经许可禁止转载!详情请阅读版权申明!