[MySQL] Index : index 생성, 삭제, 변경 > db

본문 바로가기

db

[MySQL] Index : index 생성, 삭제, 변경

작성일 13-02-15 10:48

페이지 정보

작성자서방님 조회 147회 댓글 0건

본문

MySQL

◘ index

 

 

▮ index 생성 1 (table을 만들면서 index 지정)

 

  - [문법]

        CREATE TABLE table_name (

            column_name    column_type

              ……

            index (column_name),

        );

 

  - index column은 되도록 char형이나 int형을 사용

  - index 이름은 column과 동일하게 생성됨

 

 

▮ index 생성 2 (ALTER 문장을 이용해 생성)

 

  - ALTER  TABLE  table_name  add  index  index_name  (column_name);


> index 생성 후 검색 속도의 차이

 mysql> select * from test_in id=50000;

 +-------+-------+-------+-------+-------+

 | id      | n1     | n2     | n3     | n4     |

 +-------+-------+-------+-------+-------+

 | 50000  | r      | j      | r      | j     |

 +-------+-------+-------+-------+-------+

 1 row set (0.05 sec)

 

 mysql> alter table test_in add index test_index (id);         // index 생성

 Query Ok, 51373 rows affected (4.86 sec)

 

 mysql> select * from test_in id=50000;

 +-------+-------+-------+-------+-------+

 | id      | n1     | n2     | n3     | n4     |

 +-------+-------+-------+-------+-------+

 | 50000  | r      | j      | r      | j     |

 +-------+-------+-------+-------+-------+

 1 row set (0.00 sec)
 

 

※ index로 지정하는 column 

  - primary key, unique key로 사용되는 column (자동으로 index 생성)

  - where 절에 조건으로 자주 사용되는 column

 

 

▮ index 확인

 

  - SHOW INDEX FROM <table_name>;

 

 

▮ index 삭제


  - ALTER TABLE table_name DROP INDEX index_name (column_name);

 

 

댓글목록

등록된 댓글이 없습니다.

게시물 검색
Copyright © 서방님.kr All rights reserved.
PC 버전으로 보기