SHOW INDEX
命令。,,``sql,SHOW INDEX FROM table_name;,
``,,这个命令会显示指定表的所有索引信息。create_index_if_not_exists
的存储过程,用于在表users
的列name
上创建索引:,,``sql,DELIMITER //,CREATE PROCEDURE create_index_if_not_exists(),BEGIN, DECLARE indexExists INT DEFAULT 0;,, SELECT COUNT(*) INTO indexExists FROM information_schema.statistics, WHERE table_schema = DATABASE() AND table_name = 'users' AND index_name = 'name_index';,, IF indexExists = 0 THEN, CREATE INDEX name_index ON users (name);, END IF;,END//,DELIMITER ;,
`,,以上存储过程首先检查
users表中是否存在名为
name_index`的索引,如果不存在则创建该索引。CREATE INDEX index_name ON table_name (column1, column2, ...);
。SHOW INDEX FROM
语句来显示表的索引信息。SHOW INDEX FROM your_table_name;
将列出指定表的所有索引。Powered By Z-BlogPHP 1.7.3