Skip to main content

Posts

Showing posts with the label indexing

MySql Indexing

MySql Indexing A database index is a data structure that improves the speed of operations in a table.INSERT and UPDATE statements take more time on tables having indexes where as SELECT statements become fast on those tables. The reason is that while doing insert or update, database need to insert or update index values as well. Indexes are a way to avoid scanning the full table to obtain the result CREATE TABLE person ( last_name VARCHAR(50) NOT NULL, first_name VARCHAR(50) NOT NULL, INDEX (last_name, first_name) ); So if your index has two columns, say last_name and first_name, the order that you query these fields matters a lot. This query would take advantage of the index: SELECT last_name, first_name FROM person WHERE last_name = "John" AND first_name LIKE "J%" Using Create statement CREATE INDEX techsudhir_age ON employees(emp_name, emp_age); Alter command to update index ALTER TABLE person  ADD INDEX (name); Removing Indexes DROP...