索引
創(chuàng)建索引
-- 從表的角度創(chuàng)建索引
ALTER TABLE actor ADD UNIQUE INDEX uniq_idx_firstname (first_name);
ALTER TABLE actor ADD INDEX idx_lastname (last_name);
-- 從數(shù)據(jù)庫(kù)的角度創(chuàng)建索引
CREATE UNIQUE INDEX uniq_idx_firstname USING BTREE actor (first_name);
刪除索引
ALTER TABLE actor DROP INDEX uniq_idx_firstname;
DROP INDEX uniq_idx_firstname ON actor;
強(qiáng)制使用索引
select *
from actor
force index (uniq_idx_firstname)
where first_name = 'jd'
約束
添加主鍵約束
ALTER TABLE employees_test
ADD CONSTRAINT PRIMARY KEY(id);
添加外鍵約束
ALTER TABLE audit
ADD CONSTRAINT
constraint_name
FOREIGN KEY(emp_no)
REFERENCES employees_test(id);
本文摘自 :https://www.cnblogs.com/