raindropz12 Posted April 28, 2011 Share Posted April 28, 2011 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) ); Quote Link to comment https://forums.phpfreaks.com/topic/234927-non-unique-index/ Share on other sites More sharing options...
Muddy_Funster Posted April 28, 2011 Share Posted April 28, 2011 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...) Quote Link to comment https://forums.phpfreaks.com/topic/234927-non-unique-index/#findComment-1207435 Share on other sites More sharing options...
raindropz12 Posted April 28, 2011 Author Share Posted April 28, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/234927-non-unique-index/#findComment-1207438 Share on other sites More sharing options...
Muddy_Funster Posted April 28, 2011 Share Posted April 28, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/234927-non-unique-index/#findComment-1207444 Share on other sites More sharing options...
raindropz12 Posted April 28, 2011 Author Share Posted April 28, 2011 thank you Quote Link to comment https://forums.phpfreaks.com/topic/234927-non-unique-index/#findComment-1207629 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.