4 ms·
Probably because the same can already be expressed using relations and foreign keys.
by goto11 5y ago
Probably because the same can already be expressed using relations and foreign keys.
- throwaway894345 5y agoI don't think it can. I don't believe SQL allows you to create a fkey column that points into many different tables. You can create your own pseudo fkey column that the database doesn't know is a pointer into other tables ("type erasure") but then you have to recreate referential integrity and so on yourself, and you still run into issues querying against the table that has that fkey column in a useful way.
- goto11 5y agoYou don't need a FK to point to multiple tables. You would have the reference in the other direction, from multiple different tables to one table.
- ithkuil 5y agoHow do you ensure that only one row of only one table references the row of that one table?
- alexvoda 5y agoTheoretically, this could also be achived by allowing FKs to Views. But I know of no system that allows this.
- goto11 5y agoMost databases have weak support for cross-table constraints. I believe in SQL Server you can define an indexed view on the union of the tables and then apply a unique constraint on the foreign key.