1
 CREATE TABLE news (
    id int(11) NOT NULL AUTO_INCREMENT,
    title varchar (128) NOT NULL,
    slug varchar (128) NOT NULL,
    text text NOT NULL,
    PRIMARY KEY (id),
    KEY slug (slug)
    );

What does KEY slug (slug) means in the above code?

Arjun
  • 34
  • 1
  • 8

3 Answers3

5
KEY slug (slug)

Here KEY means index, first slug is a index name (you can skip it or keep it), (slug) means creating index on slug field.

As a standard you keep keep it as-

KEY idx_slug(slug)
Zafar Malik
  • 6,734
  • 2
  • 19
  • 30
3

Looking at the MySQL documentation lead me to this:

{INDEX|KEY}

So in this case it is referring to the fact that KEY is an INDEX on the table, and it doesn't refer to a primary key or foreign key.

In the context of this line, KEY slug (slug), it is creating an index called slug on the slug field.

James
  • 15,754
  • 12
  • 73
  • 91
-1

Key slug is used to store the unique key that would be used to route to fetch your information in codeigniter you can use it by configuring the slug class