A contrived example:
Say we have two types of tools: hammers and wrenches. We have a list of work orders, and we want to track what tool was used for the hammering and what was used for the wrenching.
The problem is that wrenches can be used as hammers (not well, but that's beside the point) but hammers can't be used as wrenches.
Here's what the table structure looks like:
What I need to do is set a constraint such that the WrenchingTool field can only contain ToolNumbers that have a corresponding ToolType of "Wrench." Meanwhile, the HammeringTool field has no such constraints.
I'm stuck. Can this even be done?
Say we have two types of tools: hammers and wrenches. We have a list of work orders, and we want to track what tool was used for the hammering and what was used for the wrenching.
The problem is that wrenches can be used as hammers (not well, but that's beside the point) but hammers can't be used as wrenches.
Here's what the table structure looks like:
Code:
ORDERS
OrderNumber WrenchingTool HammeringTool
| |
| |
`--------------`-----> TOOLS
ToolNumber ToolType
What I need to do is set a constraint such that the WrenchingTool field can only contain ToolNumbers that have a corresponding ToolType of "Wrench." Meanwhile, the HammeringTool field has no such constraints.
Code:
CREATE TABLE orders (
OrderNumber integer PRIMARY KEY,
HammeringTool integer,
WrenchingTool integer,
FOREIGN KEY (HammeringTool) REFERENCES tools (ToolNumber),
FOREIGN KEY (WrenchingTool) REFERENCES tools (ToolNumber),
CONSTRAINT hammers_cant_wrench _______halp_plox__________,
);
I'm stuck. Can this even be done?