Jump to content

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

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.