Skip to content
Advertisement

Constraints using If structure

I got a data table and require some custom constraints. The data table is as following:

What i need is the following:

Is something like this even possible?

Advertisement

Answer

Please note that MySQL CHECK constraints are only enforced starting on MySQL 8.0.16. Before that, they are accepted and silently ignored.

Assuming you are using MySQL 8.0.16 or newer, you can do:

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement