MySQL: restricting two columns, so one of them is always NULL

I have a table with links from its two columns to two other PK tables. Is there a way I can limit both of these columns from having values?

I want one of them to matter and the other to NULL

Favorites:

id table_1_id table_2_id 

Table_1:

 id 

Table_2:

 id 
+4
source share
1 answer

In SQL, you can do this perfectly with CHECK constraint .

There is no direct mechanism in MySQL for imposing such a CHECK constraint. If you try to enable it, the MySQL Reference Guide states (as it is part of the standard):

The CHECK clause is parsed but ignored by all storage engines.

+4
source

Source: https://habr.com/ru/post/885500/


All Articles