database design question

Posted by Leonardo on Stack Overflow See other posts from Stack Overflow or by Leonardo
Published on 2010-01-26T10:03:11Z Indexed on 2010/05/20 20:20 UTC
Read the original article Hit count: 374

Filed under:
|
|

Hi all,

I am building a database as a simple exercise, it could be hosted on any database server, so I am trying to keep things as much standard as possible. Basically what I would like to do is a 'code' table that get referenced by other entities. I explain:

xcode
id code
r  role
p property

code
r admin
r staff
p title
....

then I would like to have some view like:

role (select * from code where xcode='r')
r admin
r staff

property (select * from code where xcode='p')
p title

then, suppose we have an entity

myentity
id - 1
role - admin (foreign key to role)
title - title (foreign key to property)

Obviously I cannot create foreign key to a view, but this is to tell the idea I have in mind. How can I reflect such behaviour using whenever possible, standard sql syntax, then as a second option, database additional features like trigger ecc... ?

Because if I tell that role and title in myentity are foreign key to 'code', instead of the views, nothing would stop me to insert a role in title field.

thanks Leonardo

© Stack Overflow or respective owner

Related posts about database

Related posts about view