If you use create a new column named bookmark
and bookmark_reference
of the type uniqueidentifier
for both tables, and your code simply puts a GUID (or the SQL function NEWID()
) when a user does a bookmark.
Your bookmark table replace item_id
with bookmark_reference
and another varchar(100)
column table_reference
.
Thus making your bookmarking functionality generic for the whole system, any table, can be used for bookmarking or any other text the user would want to record against this particular record of this particular table.
Like custom 'notes' against a customer for just this user.
To make a "public" bookmark/note, just use either a zero or a null in user_id
.
Just giving you basic ideas. The ERP Syteline from INFOR uses this type of functionality, but they use a guid (uniqueidentifer) for the user_id
equivalent field, making the table unreadable without a INNER JOIN
to the users table. So using user_id
will make everyone's life easier down the road.
So the structure would be like this:
[table: item]
id title content bookmark
1 ... ... {guid abc}
2 ... ...
3 ... ...
[table: bookmark]
bookmark_reference table_reference user_id
{guid abc} item 1
{guid def} item 1
{guid xyz} customer 2
{guid 123} user 1
Fun fact with this structure, a user could have a bookmark on a user!
Edit: Link to a StackOverflow article on using uniqueidentifier