My question is more advisory than technical. I'm writing a Facebook app in which I am fetching some information about the user, including facebook_id.
I was wondering if I should keep the user id as INT or VARCHAR in the MySQL database?
An int is usually better, because it gives better performance. If your item has a natural key which is a varchar, you could use that and it will work. But you will get a performance improvement (and some other benefits) by adding a surrogate key that is an integer.
Everyone on Facebook has a user ID number, created when they joined. The numbers aren't strictly sequential: the first few million are segmented by university, so that Harvard users were assigned 0-99999, Columbia users 100000-199999, Stanford users 200000-299999, and so on.
Your User ID is a string of numbers that doesn't personally identify you but does connect to your Facebook profile. You have a User ID automatically, whether or not you choose to create a username. Learn how to find your user ID.
Facebook uses 64-bit integers (bigint) for their user ids. So you use Bigint UNSIGNED in MySQL.
"As a reminder, in the very near future, we will be rolling out 64 bit user IDs. We encourage you to test your applications by going to www.facebook.com/r.php?force_64bit and create test accounts with 64 bit UIDs."
Edit: Facebook usernames is not the same thing as the user id. The username is of course varchar but will not be returned as the id.
Although unlikely, facebook could change the format of their ID's, so to make it future proof, I'd use a varchar.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With