I have two tables A,B. Both tables will have more than 1 million records.
A has two columns – id, photo_id. id is the primary key and photo_id is unique.
A needs to be referenced in B.
3 questions:
- Can I ignore
A‘sidand usephoto_idto link the two tables? - Is there any benefit of using the primary column as opposed to using a unique column in B?
- What difference will it make to have a foreign key? I probably won’t use foreign key since it’s not supported on the server I’m using. Will this make a significant difference when there are 1+ mil records?
Skip having an id-column. If you have a photo_id that is already unique you should use that instead. A primary key (in MySQL InnoDB) is automatically clustered, which means that the data is stored in the index, making for VERY efficient retrieval of an entire row if you use the primary key as reference.
To answer your questions:
select * from photos where 2 < id AND id < 10)