mysql - Constrain database to hold one value or the other never both -


is possible add database constraint limit row have single value in 1 of 2 columns, never more , never less? let me illustrate:

sales order table --------------------------------- id  |  person_id  |  company_id | 

rows like:

id | person_id | company_id | ---|-----------|------------|  1 |         1 |       null |  2 |         2 |       null |  3 |      null |          1 |  4 |      null |          2 | 

in illustration, source of sales order either person or company. 1 or other, no more or less. question is: there way constrain database 1) both fields can't null , 2) both fields can't not-null? i.e., 1 has null , 1 has not-null...

i know initial reaction may combine 2 tables (person, company) 1 customer table. but, example i'm giving simple example. in application 2 fields i'm working cannot combined one.

the dbms i'm working mysql.

i hope question makes sense. thank in advance help!

this may come shock...

mysql doesn't support checkconstraints. allows define them, totally ignores them.

they allowed in syntax provide compatibility other database's syntax.


you use trigger on update/insert, , use signal raise exception.


Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -