Jump to content

non-unique index


raindropz12

Recommended Posts

is it required to set non-unique index?

what is the difference between

create table headofstate{
id int not null,
lastname varchar(30) not null,
inauguration date not null
);

 

and

create table headofstate{
id int not null,
lastname varchar(30) not null,
inauguration date not null,
INDEX(inauguration)
);

Link to comment
https://forums.phpfreaks.com/topic/234927-non-unique-index/
Share on other sites

I would worry less about non-unique indexes and more about Primary Key indexes.

 

Indexes in databases do what they do everywhere else - make the process of finding things much quicker and easier IF they are used properly.  A non-unique index allows for multiple entries of the same value to be included within the indexed field (not something I think you would need in the given scenrio unless multiple preasidents were inaugurated on the same date...)

Link to comment
https://forums.phpfreaks.com/topic/234927-non-unique-index/#findComment-1207435
Share on other sites

if there are many presidents inaugurated,

which query is faster?

 

create table headofstate{
id int not null,
lastname varchar(30) not null,
inauguration date not null
);

 

or

 

create table headofstate{
id int not null,
lastname varchar(30) not null,
inauguration date not null,
INDEX(inauguration)
);

thank you.

Link to comment
https://forums.phpfreaks.com/topic/234927-non-unique-index/#findComment-1207438
Share on other sites

neither of those are queries  ;)

 

It would depend on how you are quering the data, I would expect that you would actualy want to index the last name field, and of cource set ID to a primary key.  but as I said, as no two preasidents are going to have the same inauguration date, you would use a unique index for that field if any at all.

 

And to be honest, for all the preasidents there have been, you would only be talking a difference of milliseconds between each option.

Link to comment
https://forums.phpfreaks.com/topic/234927-non-unique-index/#findComment-1207444
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.