3 ms·
But can you can not (in a simple way) prevent that both a circle and a triangle point to the same user and you can not enforce a NOT NULL for a user to must hav
by laszlokorte 5y ago
But can you can not (in a simple way) prevent that both a circle and a triangle point to the same user and you can not enforce a NOT NULL for a user to must have a favourite shape.
- goto11 5y agoYou can do that with a check constraint, although I don't know if you consider it simple. It would be cool with better support for common constraint patterns.
- laszlokorte 5y agoCould you give a concrete example for such a check constraint? I imagine each shape-table would need to have it's own check to test the existence of the same id in all other shape tables, which scales qudratically. Or if you inverse the FK to make the user-table reference the shape tables you would need multiple potential nullable columns and a check constrain that exactly one is non-null. And it would still not solve the query side of things.
- Twisell 5y agoAre you by any chance generating GPT-3 comments as part of an experiment? If not please take time to actually dive into modern SQL concepts there is likely a way to achieve your goal but I personally consider that it's pretty rude to ask random strangers a proof for a complex and loosely defined problem in the comments section. Stack Exchange should be a better place for instance.
- goto11 5y agoCheck constraints are just SQL expressions, so in pesudocode it would be something like: (SELECT COUNT(*) shape JOIN square JOIN circle) = 1 How conveniently this can be expressed depend on the database system in question. But if we are talking about adding features to SQL, it could have built-in support for such a constraint, just as there is built-in support for say foreign key constraints.