mysql - primary key with multiple column lookup -


i new databases. if make primary key 2 columns, userid , dayofweek. how can search primary key?

(dayofweek int 1 = monday, 2 = tuesday, etc.)

would use:

select *   userid = 1     , dayofweek = 4 

would scan entire database or use information provided primary key? there more appropriate query use?

a primary key index internally other index, except you're explicitly saying this key uniquely identifies record. it's index "must unique" constraint imposed on it.

whether db uses composite primary key depends on how specify key fields in query. given pk(userid, dayofweek), then

select * mytable (userid = 1); select * mytable (userid = 1) , (dayofweek = 4); 

would both use primary key index, because you've used fields in order they're specified within key.

however,

select * mytable (dayofweek = 4) 

will not, because userid not specified, , userid comes before dayofweek in key definition.


Comments

Popular posts from this blog

php - What is the difference between $_SERVER['PATH_INFO'] and $_SERVER['ORIG_PATH_INFO']? -

fortran - Function return type mismatch -

queue - mq_receive: message too long -