mysql 如何在创建索引index_name之前判断该索引是否存在?

静默飘闪 2011-03-23 09:54:02
网上搜了半天都没找出个头绪,其他数据到是有,但是mysql里面貌似不能用select查出索引记录,而show index查出来的貌似也不能用where exists来判断,那么就更别提在create index index_name 后面加where了..
刚刚还想说'在建立索引前判断一下索引是否存在还是很有必要'了.
但刚才测试了一下,即使在不存在索引的情况下要删除这个索引,虽然有提示出错,但程序还是一样可以正常运行,所以,并没有太大影响.
不过好歹还是应该有可以判断的方法吧.
...全文
1439 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
静默飘闪 2011-03-27
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 life169 的回复:]

引用 1 楼 seai 的回复:

drop index if exists index_name;
create index index_name ......;

+++
[/Quote]
此外,百度里面有人说,drop index index_name on table 语法是不支持if exists的.
静默飘闪 2011-03-27
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 seai 的回复:]

drop index if exists index_name;
create index index_name ......;
[/Quote]
不知道你有没有试验过,我在phpmyadmin里面是不能用的.
我现在在试试在终端里面行不行.
一样不行,错误如下.我建立的全文索引,索引名为content

mysql> drop index if exists content
-> ;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server version for the right syntax to use near 'if ex
ists content' at line 1
seai 2011-03-24
  • 打赏
  • 举报
回复
drop index if exists index_name;
create index index_name ......;
life169 2011-03-24
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 seai 的回复:]

drop index if exists index_name;
create index index_name ......;
[/Quote]
+++

21,886

社区成员

发帖
与我相关
我的任务
社区描述
从PHP安装配置,PHP入门,PHP基础到PHP应用
社区管理员
  • 基础编程社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧