Data model - PRIMARY KEY numbering issue

好久不见. 提交于 2019-12-11 17:33:00

问题


I have the following issue:

I have this entity, let's call it ENTITY_THREE, which is part of a arc barred relationship:

Three entities ENTITY_ONE, ENTITY_TWO and ENTITY_THREE which are part of an arc barred relationship

Please note that ENTITY_THREE has a composite primary key: ID, ID_OF_ONE, ID_OF_TWO and ENTITY_TWO has a composite primary key as well: ID, ID_OF_ONE.

Now, according to the description of the assignment, if ENTITY_TWO has more than 1 of ENTITY_THREE, ENTITY_THREE needs to be numbered by ENTITY_TWO, like so:

ENTITY TWO:

ID
1
2

ENTITY THREE:

ID  ID_OF_TWO
1   1
2   1
3   1
1   2
2   2
3   2

So, what I basically want is that when you use an INSERT statement, you must not provide the ID: it adds it for you automatically. But the ID is numbered by a foreign key: all records with an ID_OF_TWO 1, let's say 5, will be numbered 1 through 5, all records with an ID_OF_TWO 2, let's say 3, will be numbered 1 through 3, and so on …

Is there any way (a TRIGGER maybe?) I can accomplish this?

@EDIT:
Earlier on I talked about an arc relationship, but what I actually mean't was a barred relationship, my bad.

@Update:
I saw something a couple of days ago that might work, but I'm not too sure. I'm going to try it anyways. I will let you guys know if it worked or not …

来源:https://stackoverflow.com/questions/50486727/data-model-primary-key-numbering-issue

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!