In MySQL how to set index to the table?

被刻印的时光 ゝ 提交于 2019-12-24 00:56:35

问题


In MySQL how to use the Index concept for MySQL tables.


回答1:


Syntax for adding index to existing table.

ALTER TABLE table_name ADD INDEX column_name

A simple example

CREATE TABLE employee_records (name VARCHAR(50), employeeID INT);
CREATE INDEX id_index ON employee_records(employeeID);

creating index while creating table

CREATE TABLE employee_records (
    name VARCHAR(50), 
    employeeID INT, INDEX (employeeID)
);



回答2:


To add an index to a table in MySQL:

ALTER TABLE [table name] ADD INDEX ([column name], ...);



回答3:


ALTER TABLE table_name ADD INDEX index_name (col_name)

OR

CREATE INDEX index_name ON table_name(index_name)



来源:https://stackoverflow.com/questions/6731048/in-mysql-how-to-set-index-to-the-table

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!