Reputation: 5818
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:
A
's id
and use photo_id
to link the two tables? Upvotes: 0
Views: 143
Reputation: 2284
I would only remove your id column if you are positive that photo_id values will never change. If multiple rows of your B table reference a specific A row and the photo_id for that row needs to be updated, you will want to be referencing the id column from your B table.
Upvotes: 0
Reputation: 45721
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
)Upvotes: 5