4 ms·
>Now, when a device is linked to a user, both should be on the same organization, right? I don't see how to easily do that as a constraint I'm not exactly an e
by hnarn 9y ago
>Now, when a device is linked to a user, both should be on the same organization, right? I don't see how to easily do that as a constraint
I'm not exactly an expert when it comes to SQL either, but in this case wouldn't it be better if the "Device" table had two columns: "UserOwner" and "OrgOwner" which in turn have FK connections to "Users" and "Organizations".
If the logic is that every device is only owned by a user or an org (never both) at any time, you could constrain: check(UserOwner is null or OrgOwner is null).