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 333037
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T09:55:26+00:00 2026-05-12T09:55:26+00:00

I am grappling with a database design issue at the moment, I will present

  • 0

I am grappling with a database design issue at the moment, I will present a simplified scenario of what is going on:

Lets say I have four tables, Equipment, CurrentState, StateValue, StateType with the following schemas:

Equipment
------------
Id (PK),
Name


CurrentState
------------
Id (PK),
EquipmentId (FK) (IX),
StateValueId (FK),
StateTypeId (FK) (IX)


StateValue
------------
Id (PK),
StateTypeId (FK),
Name


StateType
-----------
Id (PK),
Name

A piece of equipment can have several different CurrentStates belonging to different StateTypes, hence the Unique Index (IX). A StateType is basically a state machine and StateValue contains the values for each state machine.

Now, my question, well 2 questions, is around the StateTypeId foreign keys in the CurrentState and StateValue tables that determine what StateType a CurrentState record is and what StateType a StateValue record is.

First of all, is having this type of relationship bad design in terms of referential integrity? My guess is that it IS bad design as there should only be one link between the CurrentState table and the StateType table, and this is via the StateValue, else a CurrentState record could end up having two different StateTypes (one via the direct FK and the other via the StateValue tables FK)…

But the second question comes: If I should not have a StateTypeId FK in the CurrentState table, how can I enforce the Index, that is ensure that there is not two CurrentState records for a single EquipmentId that have StateValueIds pointing to StateValue records of the same StateType…

Do I have to use a trigger when inserting into the CurrentState table to check that the rules are followed? I have never used triggers before, so I will need to do a bit of research. I am also using Entity Framework and have no idea what the implications are with this (there shouldn’t be any in theory).

  • 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-12T09:55:26+00:00Added an answer on May 12, 2026 at 9:55 am

    Yes, this is bad practice, since you can have two different State Types for one current value. Drop the StateTypeId column out of CurrentState, and have it only go through StateValueId. Your unique index should be on CurrentState and StateValueId.

    Of course, if you insisted on having StateTypeId in CurrentState, you could set up a check constraint that would make sure that StateTypeId was equal to the StateTypeId from StateValueId. But this is really roundabout. It’s much cleaner and more maintainable to leave them all in their own silos.

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

Sidebar

Related Questions

I have some difficulties grasping some concepts. Grateful for help. Let's say you have
I'm having trouble grasping reflection in C#, so I'm going to put my specific
I have seen many reportlab graphing examples. Generating the graph is not the problem,
I am currently trying to find a simple, easy way to publish/broadcast stock tick
I'm making a simple JavaScript graphing library using the canvas element. I really suck
I am trying to add Series binding to the Visifire graphing controls set. To
I was reading over http://android-developers.blogspot.com/2009/04/backward-compatibility-for-android.html But I'm really not grasping how to ignore certain
I've been reading the android documentation on reflection, but i'm just not really grasping
To start off, this really isn't CodeIgniter specific. I'm having trouble grasping an idea,
I'm trying to understand the ControlStyle property in Delphi 2007, but I'm having trouble

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.