Database design - passenger, driver, wallet. How to handle multiple foreign keys with Id and type fields?
You cannot have that directly, but you can do the following:


Have two foreign key columns driverid and passengerid in wallet that reference the respective tables.
Add a check constraint that force one of the foreign key columns NULL and the other NOT NULL based on usertype.

CHECK (usertype = 'driver'    AND driverid IS NOT NULL AND passengerid IS NULL
    OR usertype = 'passenger' AND driverid IS NULL AND passengerid IS NOT NULL)

If you want, add a view on wallet that uses coalesce to map both foreign key columns to a single one.