New answers tagged

0

I only skimmed through the answers, so I might have missed a similar answer. The idea is to use a generated column that is either the p.k or a constant that does not exist as a value for the p.k. create table foo ( bar int not null primary key , chk char(1) check (chk in('Y', 'N')) , some_name generated always as ( case when chk = 'N' ...


2

Here's a solution for MySQL and MariaDB using virtual columns that's a bit more elegant. It requires MySQL >= 5.7.6 or MariaDB >= 5.2: MariaDB [db]> create table foo(bar varchar(255), chk boolean); MariaDB [db]> describe foo; +-------+--------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +-------+------...



Top 50 recent answers are included