Writing for 11/6 Wednesday

Writing for 11/6 Wednesday

by Nick Jonas -
Number of replies: 0

Indexes are an essential component of any large database nowadays, as they excel at increasing the efficiency of various operations. An index is simply a structure of references to your data, making it easier to look up in some operations. Another powerful use of indexes is the ability to join different tables in a database, as a specified index isn’t exclusive to a single table. A good analogy for what an index is is a textbook. When reading a textbook, it's often hard to keep track with all vocabulary and analogies used. That’s why in most textbooks there’s an index at the end of the book, allowing readers to quickly locate words or concepts via page number.

Obviously, many SQL databases have indexes built into them, with some even containing multiple indexes for compatibility with other tables. However, in case you forget to put in an index for your table, SQL has a few nifty functions to help out. One can simply create an index for one or more attributes in their tables by simply typing:


CREATE INDEX <index_name>

ON table_name(attribute_name,second_attribute(if you want more to be connected))


Likewise, if you want to delete an index, SQL languages also can do that. This however differs in each language and it may get confusing if one switches frequently. To be consistent with work in class, the command for deleting an index goes as follows:


ALTER TABLE table_name

DROP INDEX index_name;


While indexes themselves may seem fairly simple, their purpose in databases are incredibly in regards to efficiency. 

Sources:


Good general explanation for indexes in databases with examples in real life:

https://www.essentialsql.com/what-is-a-database-index/


W3school tutorial on indexing:

https://www.w3schools.com/sql/sql_ref_index.asp