删除索引,删除列
代码语言:javascript复制mysql> show create table catworld4G
*************************** 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.00 sec)
mysql> drop index idx_test on catworld4;
Query OK, 0 rows affected (0.16 sec)
Records: 0 Duplicates: 0 Warnings: 0
mysql> show create table catworld4G
*************************** 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`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1
1 row in set (0.00 sec)
mysql> alter table catworld4 drop column test;
Query OK, 0 rows affected (4.24 sec)
Records: 0 Duplicates: 0 Warnings: 0
mysql> show create table catworld4G
*************************** 1. row ***************************
Table: catworld4
Create Table: CREATE TABLE `catworld4` (
`id` int(11) NOT NULL,
`name` varchar(30) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1
1 row in set (0.01 sec)
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>
代码语言:javascript复制Note: 来一个危险的操作 rename table
mysql> alter table catworld4 rename to abc;
Query OK, 0 rows affected (0.14 sec)
mysql> desc catworld4;
ERROR 1146 (42S02): Table 'my4.catworld4' doesn't exist
mysql> show tables;
------------------
| Tables in cctest |
------------------
| catworld |
| catworld4 |
------------------
2 rows in set (0.00 sec)
mysql>
mysql> alter table abc rename to catworld4;
ERROR 1064 (HY000): op table not in schema----ABC
mysql>