Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

So I originally thought I was going to have a one to many relationship in a database with the following tables


Originally I was going to have an FK in ATTRIBUTE_JSON_MAP pointing to ENTITY_JSON_MAP. I was going to the Attribute table with


Now however I've realized that I need to make it a many to many relationship, so I've created a mapping table, but now I've lost the ability to make sure that I don't get duplicates of that combination.

I was hoping there was still a way to do this. Inserting/deleting tables doesn't need to be fast, as the table will not be inserted or deleted at run time.

share|improve this question
up vote 0 down vote accepted

If I understand you correctly, your original

Unique (name, json_map_enum, entity_json_map_fk)

Is made up of

name: name of the attribute json_map_enum: the position of this attribute in the entity entity_json_map_fk: reference to entity

You should be able to enforce this in the mapping table as well.

CREATE TABLE Entity_Attribute_Map (
    ATTRIBUTE_JSON_MAP_fk int references ATTRIBUTE_JSON_MAP(id),
    entity_json_map_fk int references entity_json_map(id),
    JSON_MAP_ENUM int,
    Primary Key (ATTRIBUTE_JSON_MAP_fk, entity_json_map_fk, JSON_MAP_ENUM)
share|improve this answer
So that will make it so I'll never have an entity mapped to two attributes with the same name and enum? – DrSammyD Oct 25 '12 at 13:58

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.