Jump to content

[SOLVED] Indexes


waynewex

Recommended Posts

I've only began using indexes on my db. I'm able to add an index to a specific column, but I'm still not sure as to how I will be able to go about:

 

  • Using them (indexes) in my queries and
  • Updating them.

Could somebody give a small example. Here is one of my tables.

 

$mysqli->query("
CREATE TABLE IF NOT EXISTS users(
  user_id INT(11) NOT NULL AUTO_INCREMENT,
  username VARCHAR(22) NOT NULL UNIQUE,
  email VARCHAR(120) NOT NULL UNIQUE,
  name VARCHAR(100) NOT NULL,
  user_type TINYINT(3) NOT NULL,
  password TEXT NOT NULL,
  dob DATE NOT NULL,
  gender TINYINT(1) NOT NULL,
  location VARCHAR(100) NOT NULL,
  last_login DATETIME NOT NULL,
  signup_date DATETIME NOT NULL,
  incorrect_logins TINYINT(1) DEFAULT 3,
  INDEX email_index (email),
  INDEX username_index (username),
  INDEX user_type_index (user_type),
  INDEX name_index (name),
  INDEX location_index (location),
  INDEX signup_date_index (signup_date),
  INDEX last_login_index (last_login),
  INDEX password_index (password),
  PRIMARY KEY(user_id))") or die(mysqli_error($mysqli));

 

I've added an index to anything that I might end up searching for.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.