B
B
Bepack Green2020-03-26 08:49:31
Database design
Bepack Green, 2020-03-26 08:49:31

When to use a foreign key and when a literal notation?

When to use a link pointing to another table, and when to write it as a literal?

For example rbac:
There is a table users (user):
id | login
And there is a table of user roles (role):
id | name
There is also a table of assignments of these roles (role_assignment):
id | role_id*** | user_id

I met different options, somewhere role_id is a foreign key indicating an entry in role, and somewhere there the role name is simply written down

Why and in what cases - it is necessary to do not a foreign key, and to write down a name?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
Konstantin Tsvetkov, 2020-03-26
@tsklab

Text - when the role has a separate semantic load, for example, a role in a film.
Code from a linked table - when the role defines common functionality, such as access level.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question