I have to create a table, with either first name and last name of a person, or a name of an organization. There has to be exactly one of them. For example one row of the table is –
first_name last_name organization ---------- --------- ------------ John Smith null
or another row can be –
first_name last_name organization ---------- --------- -------------------- null null HappyStrawberry inc.
Is there a way to define this in SQL language? Or should I just define all three columns being able to get null values?
You could use a check constraint, like:
Another way is to add a
typecolumn (EAV method):