Answer the question
In order to leave comments, you need to log in
Automatic set in mysql?
Let's say there are three bases: Users, Groups and a linking user-group.
The first two have two fields, id and name. The third has three: id, uName, gName.
The uName and gName fields are of type set.
And now the question.
Maybe someone knows how when adding, for example, a user named John, to the user-group table in the uName field, the name was automatically added to the set ( set('John') )? And in general, is there such a possibility?
PS Do not ask why and why. I understand that there is not much logic here. Just need an example, or ways of similar implementation. Also it is not necessary, please, to advise to connect on keys. I know this very well.
Answer the question
In order to leave comments, you need to log in
Why set? A link table typically consists of a pair of foreign keys to the linked tables. Those. usually two ints and a composite primary key.
Possibility to write a trigger. But first I would like to understand the meaning.
You can, of course, implement it through a trigger and ALTER TABLE, but in general SET is not intended for this. SET and ENUM are used when the list of values is known in advance and limited.
PS And what, you can have all users at once in this field?
and why the user should be duplicated in 2 tables at all, the name is written in the user, the user group is written in the ID from the user table
, you can generally make the user group not a table, but a view. And you can also have 2 tables, users - id, username, groupid and groups - id, groupname
and the connection will be through users.groupid = groups.id
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question