My system uses a table of users with several elements including their online status. Now I would like to add a feature so each user can add a contact i.e an existing user from the database into their list of friends or contacts showing their name and online status. However I need any changes in the online status to updated on the contact list as they happen so creating a new table wouldn’t help.
I have been looking into views for this but don’t have too much experience with databases to I would like to know if this is the correct way of going about it and a bit more detail on how to do it.
Here are the steps I was thinking of:
- When users registers, create a view i.e view_name = username_view.
- To add a contact select data from main users table and add to user’s view
- To delete a contact delete selected data from view.
I am not sure if this is possible with views so if it isn’t can some please help me out.
Thanks.
ER databases = Entites and Relations databases handle that by have one table whit the entites “users”, and one table for the relationship “friends” that connect a user to another user.
a query for that can be:
Exemple:
a user table, for the entity user
exemple users
a friends tabel, for relations between two users, (not one per user, just one)
if Anna adds Beril and Carl as friends, and Carl adds David and Erik as friends, the content of the table going to be:
if we want to list the names of Annas friends, and we allredy know that Annas user_id = 1, then we can use this query (like the one above)