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

  • Home
  • SEARCH
  • 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

Ask A Question

Stats

  • Questions 204k
  • Answers 204k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Have you tried loading it in - (UITableViewCell *)tableView:(UITableView *)tableView… May 12, 2026 at 8:43 pm
  • Editorial Team
    Editorial Team added an answer Wikipedia has a list of various STM implementations. May 12, 2026 at 8:43 pm
  • Editorial Team
    Editorial Team added an answer n is the degree of the polynome (and a polynome… May 12, 2026 at 8:43 pm

Related Questions

In Java, you can do the following : public interface IEngine{} public interface ICoolEngine
Im trying to wrap my head around MVVM. I understand a lot of it,
I noticed that doxygen uses the graphviz library for creating diagrams. Have you ever
I am working with django and having a hard time grasping how to do

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.