MySQL 联合索引创建指南:提高查询效率
在 MySQL 中,可以通过以下语法来创建联合索引:
CREATE INDEX index_name ON table_name (column1, column2, column3, ...);
其中,'index_name' 为索引名称,'table_name' 为需要创建索引的表名,'column1, column2, column3, ...' 为需要创建联合索引的字段名,多个字段名用逗号隔开。
例如,创建 'orders' 表中的 'customer_id' 和 'order_date' 字段的联合索引,可以使用以下语句:
CREATE INDEX idx_customer_order_date ON orders (customer_id, order_date);
这样就创建了一个名为 'idx_customer_order_date' 的联合索引,包含 'customer_id' 和 'order_date' 两个字段。这个联合索引将会提高按照 'customer_id' 和 'order_date' 进行查询的速度。
原文地址: https://www.cveoy.top/t/topic/oBmW 著作权归作者所有。请勿转载和采集!