Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Probably because the same can already be expressed using relations and foreign keys.


I 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.


You 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.


How do you ensure that only one row of only one table references the row of that one table?


Most 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.


Theoretically, this could also be achived by allowing FKs to Views. But I know of no system that allows this.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: