添加列
mysql> desc catworld4;
+-------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+-------------+------+-----+---------+-------+
| id | int(11) | NO | PRI | NULL | |
| name | varchar(30) | YES | | NULL | |
+-------+-------------+------+-----+---------+-------+
2 rows in set (0.00 sec)
mysql> alter table catworld4 add test int;
Query OK, 0 rows affected (4.22 sec)
Records: 0 Duplicates: 0 Warnings: 0
mysql> desc catworld4;
+-------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+-------------+------+-----+---------+-------+
| id | int(11) | NO | PRI | NULL | |
| name | varchar(30) | YES | | NULL | |
| test | int(11) | YES | | NULL | |
+-------+-------------+------+-----+---------+-------+
3 rows in set (0.01 sec)
mysql> 修改列类型
mysql> alter table catworld4 modify test varchar(10);
Query OK, 10 rows affected (0.91 sec)
Records: 2 Duplicates: 0 Warnings: 0
mysql> desc catworld4;
+-------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+-------------+------+-----+---------+-------+
| id | int(11) | NO | PRI | NULL | |
| name | varchar(30) | YES | | NULL | |
| test | varchar(10) | YES | | NULL | |
+-------+-------------+------+-----+---------+-------+
3 rows in set (0.04 sec)
mysql>添加索引
mysql> create index idx_test on catworld4(test);
Query OK, 0 rows affected (6.00 sec)
Records: 0 Duplicates: 0 Warnings: 0
mysql> show create table catworld4\G
*************************** 1. row ***************************
Table: catworld4
Create Table: CREATE TABLE `catworld4` (
`id` int(11) NOT NULL,
`name` varchar(30) DEFAULT NULL,
`test` varchar(10) DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `idx_test` (`test`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1
1 row in set (0.01 sec)
mysql> 本文系转载,前往查看
如有侵权,请联系 cloudcommunity@tencent.com 删除。