Let's say I sell books and CDs, so I have table in database for both of them, because I can't use same table for both. Also I have a stock table for both of them, which refers through foreign key to according item's table. Like this:
book book_stock
----- ----------
bookID book_stockID
title bookID
price
cd cd_stock
----- ----------
cdID cd_stockID
title cdID
price
But I'd like to have one general stock table, which referes to both item's tables depending on type
column.
book stock
----- ----------
bookID stockID
title type
itemID
price
cd
-----
cdID
title
So, how to make such constraint which checks more than one table?