I have a database of TCG cards and I am trying to decide a primary key. I settled with a surrogate key initially but I realized that sometimes, there are cards that I forget to add, like promo cards for example. This is problematic with the surrogate key because they get added to the database with the latest auto increment and I didn't want their IDs to depend on the order they were inserted. I was thinking maybe I could do a hash on some of the card features and use that as the primary key instead?
Take for example the following pseudo-code:
// set code, date released, collector number, name
$crc = crc32(implode(',', ['A', '1993-08-03', '232a', 'black lotus']));
echo $crc; // 4199975187
The possible amount of cards hovers just around 25k now and grows around 100-300 every 6 months.
- At this rate, there won't be a collision right?
- Is this good practice? Do I have any other good alternatives?
I know I can make the hash shorter by converting it to base 62
but I will be joining these to the users' inventories table so I think maintaining these in int
will be the best option.