sql - Correct way to handle anonymous and registered users -


i developing game application , debating correct way handle user owner of played game.

you can either play anonymous guest has provide location or registered user. users stored in database. once complete game database entry added score , want log played game.

the table looks follows:

users ( id | user_name | password | country ) games ( id | user_id | score )

as of store reference users(id) in games(user_id), how should handle anonymous users though?

one way store every anonymous user id , location , add column games called anonymous_id. 1 of user_id or anonymous_id have null every game depending on if player registered or not.

another way add anonymous users user table , allow user_name , password null.

is there better way handle this?

any advice appreciated.

if store countries elsewhere, not add occurence in user table each anonymous user. because each anonymous user, you'd have 2 inserted rows (1 in user, 1 in games).

instead have

games ( id | user_id | score | country_id)  

user_id , country_id both nullable foreign keys.

when registered user ends game, store user_id. can leave country_id null because case of duplicate data. when anonyomous user ends game, store score , country_id in games.

you identify anonymous users filtering user_id null in games, , still have possibility have ranking user, , country.


Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -