Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7589785
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T20:14:49+00:00 2026-05-30T20:14:49+00:00

20120304 – Streamlined question Suppose we have entities R, D and E and this

  • 0

20120304 – Streamlined question

Suppose we have entities R, D and E and this relational cardinalities

  • R < n:m > D
  • D < 1:n > E

The mapping of this specification is straight forward, but we have another requirement:

  • R < n:m > E

Side condition: E1 might only get ‘assigned’ to an R1, if E1 is related to some D1 and this D1 is related to the R1.

Unfortunately, even if E2 is related to a D2, which is related to an R2 – E2 might not be related to R2.

  • I’m in search of a relational DB model.
  • A model, which doesn’t require multiple updates if a D gets detached from an Ra and reattached to another Rb. In this case, all Es of D need to get detached from Ra and attached to Rb too.

20120305 – Workaround?

A friend propose to create an entity DxR which links its D and its R by means of a tuple (D,R). Then create a relation

  • DxR < n:m > E

Hm…

20120302 – Original question

System is composed of top level zones (Z). A zone may have several regions (R).

So called departments (D) may be assigned to regions. One department may get assigned to more than one region, only if each region belongs to a different zone.

Finally, employees (E) belong to one and only one department.

Employees may get assigned to a region only if, employee’s department belongs to the region.

Important: An employee need not belong to all regions its department belongs to.

Assume, that in the following graphics E1 belongs to D1. E1 should also belong to R1, but not belong to R2 – although D1 belongs to R1 and R2:

-     Z            Z
-   __|___      ___|___
-   R1   R      R2    R
-    \_________/
-     D1         

Q: Please propose the relations DB’s table structure which models the above specification?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T20:14:50+00:00Added an answer on May 30, 2026 at 8:14 pm

    This question is very specific in one sense and some people might argue that it is too localized. There is, however, one more generally applicable idea that might be useful to other people in the future, so it isn’t necessarily true that the question is too specific.

    The really interesting part of these business rules is this one: (my emphasis added)

    One department may get assigned to more than one region, only if each
    region belongs to a different zone
    .

    Here is a schema that captures almost all of the stated business rules declaratively without having to resort to any triggers.

    create table ZONE
    ( ID int not null
    , NAME varchar(50) not null
    , constraint PK_ZONE primary key clustered (ID)
    )
    
    create table REGION
    ( ZONE_ID int not null
    , REGION_ID int not null
    , NAME varchar(50) not null
    , constraint PK_REGION primary key clustered (ZONE_ID, REGION_ID)
    , conttraint FK_REGION__ZONE foreign key (ZONE_ID) 
        references ZONE (ID)
    )
    
    create table DEPARTMENT
    ( ID int not null
    , NAME varchar(50) not null
    , constraint PK_DEPARTMENT primary key clustered (ID)
    )
    
    create table EMPLOYEE
    ( ID int not null
    , NAME varchar(50) not null
    , DEPT_ID int not null
    , constraint PK_EMPLOYEE primary key clustered (ID)
    , constraint FK_EMPLOYEE__DEPARTMENT foreign key (DEPT_ID) 
        references DEPARTMENT (ID)
    )
    

    The above tables are pretty obvious. However, there is one particular quirk: The REGION table has a compound primary key that includes the FK to ZONE. This is useful for propagating the constraint about departments having to be distinct within a zone.

    Assigninging departments to regions requires an intersection table:

    create table DEPT_ASGT -- Department Assignment
    ( REGION_ID int not null
    , DEPT_ID int not null
    , ZONE_ID int not null
    , constraint PK_DEPT_ASGT (REGION_ID, DEPT_ID)
    , constraint FK_DEPT_ASGT__REGION foreign key (ZONE_ID, REGION_ID) 
        references REGION (ZONE_ID, ID)
    , constraint FK_DEPT_ASGT__DEPARTMENT foreign key (DEPT_ID) 
        references DEPARTMENT (ID)
    , constraint UN_DEPT_ASGT__ZONES unique nonclustered (ZONE_ID, DEPT_ID)
    )
    

    This intersection table is pretty normal insofar as it has a foreign key to each of the tables that it links. What is special about this intersection table is the unique constraint. This is what enforces the rule that a department can’t be in two different regions within the same zone.

    Lastly, we need to map employees into departments and into regions. This requires another intersection table:

    create table EMP_ASGT -- Employee Assignment
    ( REGION_ID int not null
    , DEPT_ID int not null
    , EMPLOYEE_ID int not null
    , constraint PK_EMP_ASGT (REGION_ID, DEPT_ID, EMPLOYEE_ID)
    , constraint FK_EMP_ASGT__DEPT_ASGT (REGION_ID, DEPT_ID) 
        references DEPT_ASGT (REGION_ID, DEPT_ID)
    , constraint FK_EMP_ASGT__EMPLOYEE (EMPLOYEE_ID) refernces EMPLOYEE (ID)
    )
    

    You will note that the EMPLOYEE table has a foreign key to DEPARTMENT – That enforces the rule that each employee can belong to only one department. The EMP_ASGT table adds the details about which regions the employee participates in. Since an employee may not be involved in every region that his or her department is assigned to, the EMP_ASGT table connects employees to just those regions where they have some involvement.

    Here is the one place where a trigger or some other procedural logic is needed. You need to make sure that EMPLOYEE.department_id stays consistent with the records in EMP_ASGT. You could try to push this into the declarative referential integrity by making the PK of EMPLOYEE a compound of ID and DEPT_ID, but that would force you to decide whether you want to violate 3NF or make your employee department changes a procedurally ugly mess. At the end of the day, a little trigger to make sure that EMP_ASGT doesn’t disagree with EMPLOYEE.DEPT_ID would be much less trouble.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a filename in the following format: xx_xx_xx_xx/Run02/isf2sync_output/xx_xx_xx_xx_xx_Run02_xxx3_20120301_144327/xx_xx_xx_xx_xx_Run02_xxx3_20120301_144395.x.x.x.log I want to extract the
I have a weird little problem. When I run: import pygraphviz as pgv a
Have A really simple form that isnt sending any data back to my controller.
I have a table with 2 rows, one of which represents date and the
I need some suggestions in writing a regular expression pattern My string would be
I'm trying to parse string representation of date. It looks like 20120306 14:21:35 MSK
Some data would be organized thusly: ID DATE COUNT1 COUNT2 A 20120101 1 2
I use GDataDB as online INI file to save user's settings on clouds. I
Can someone help me with a perl one liner to get the following? It
I've defined a build in TFS 2010 with a drop location like \server\BuildDrop\. When

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.