如果我删除MySQL列而不先删除其索引会发生什么? [英] What happens if I drop a MySQL column without dropping its index first?

查看:154
本文介绍了如果我删除MySQL列而不先删除其索引会发生什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用我的一个MySQL表,我删除了列 col1 ,然后从包含它的唯一索引(col0,col1,col2,col3)中删除它。

With one of my MySQL tables, I dropped column col1 before I drop it from a unique index (col0, col1, col2, col3) that contains it.

MySQL会自动处理吗?在删除列col1之后,以前(col0,col1,col2,col3)的唯一索引似乎自动更改为(col0,col2,col3)。

Is it automatically taken care of by MySQL? It seems the unique index that was previously (col0, col1, col2, col3) was automatically changed to (col0, col2, col3) after I deleted the column col1.

它是一个问题还是我必须删除唯一索引并将其重新创建为(col0,col2,col3)?

Is it going to be a problem or do I have to drop the unique index and re-create it as (col0, col2, col3)?

推荐答案

根据 MySQL 5.1参考手册


如果从表中删除列,
列也会从任何
索引中删除他们是一部分。如果构成索引的所有
列都是
,那么索引也会被删除。
如果您使用CHANGE或MODIFY来缩短
a列,其中
列上的索引存在,并且结果列
长度小于索引长度
MySQL会自动缩短索引

If columns are dropped from a table, the columns are also removed from any index of which they are a part. If all columns that make up an index are dropped, the index is dropped as well. If you use CHANGE or MODIFY to shorten a column for which an index exists on the column, and the resulting column length is less than the index length, MySQL shortens the index automatically.

这篇关于如果我删除MySQL列而不先删除其索引会发生什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆