MySQL删除字段

时间:2014-05-09 16:55:21

标签: mysql alter-table delete-row

为什么我无法从MySQL数据库中删除字段?

mysql> describe Clients;

+-------------+--------------+------+-----+---------+----------------+
| Field       | Type         | Null | Key | Default | Extra          |
+-------------+--------------+------+-----+---------+----------------+
| id          | int(11)      | NO   | PRI | NULL    | auto_increment |
| name        | varchar(255) | NO   |     | NULL    |                |
| shurname    | varchar(255) | NO   |     | NULL    |                |
| email       | varchar(255) | NO   |     | NULL    |                |
| password    | varchar(255) | NO   |     | NULL    |                |
| userId      | int(11)      | NO   |     | NULL    |                |
| userMessage | varchar(255) | YES  |     | NULL    |                |
| userName    | varchar(255) | YES  |     | NULL    |                |
| pwd         | varchar(255) | YES  |     | NULL    |                |
| surname     | varchar(255) | YES  |     | NULL    |                |
+-------------+--------------+------+-----+---------+----------------+
10 rows in set (0.00 sec)

mysql> ALTER TABLE Clients DROP userId;
^CCtrl-C -- sending "KILL QUERY 104" to server ...
Ctrl-C -- query aborted.
ERROR 1317 (70100): Query execution was interrupted
mysql> ALTER TABLE Clients DROP userMessage;

它没有完成,它卡住了,不删除....我想删除userId,userMessage,userName,pwd和surname。

2 个答案:

答案 0 :(得分:0)

如果您先删除自动增量并删除主键,则应该可以删除该字段。也许只是删除自动增量会做到但不确定。无论如何,其他字段都应该删除。

答案 1 :(得分:0)

我甚至无法删除作为root的表:

mysql> show tables;
+-------------------------+
| Tables_in_Hoteles_Compu |
+-------------------------+
| Clients                 |
| Coords                  |
| Hotels                  |
| Rate                    |
| Regions                 |
+-------------------------+
5 rows in set (0.00 sec)

mysql> drop table Coords;
Query OK, 0 rows affected (0.04 sec)

mysql> drop table Clients;