-- 创建表时建立索引
CREATE TABLE employees (
id INT NOT NULL,
name VARCHAR(100),
position VARCHAR(100),
salary DECIMAL(10, 2),
INDEX idx_name (name) -- 在创建表时为 'name' 列创建索引
);
-- 为现有表添加索引
ALTER TABLE employees ADD INDEX idx_position (position); -- 为 'position' 列创建索引
-- 创建唯一索引,确保列中的值是唯一的
CREATE UNIQUE INDEX idx_unique_salary ON employees (salary); -- 为 'salary' 列创建唯一索引
-- 创建组合索引(多个列的联合索引)
CREATE INDEX idx_name_position ON employees (name, position); -- 为 'name' 和 'position' 列创建联合索引
-- 删除索引
DROP INDEX idx_name ON employees; -- 删除名为 'idx_name' 的索引
ALTER TABLE 语句来添加索引。DROP INDEX 语句可以删除不再需要的索引。上一篇:mysql中唯一索引的关键字是
下一篇:mysql字符串转时间戳
Laravel PHP 深圳智简公司。版权所有©2023-2043 LaravelPHP 粤ICP备2021048745号-3
Laravel 中文站