sql >> Base de Datos >  >> RDS >> Oracle

Índice único condicional en la base de datos h2

En H2, podría usar una columna calculada que tenga un índice único:

create table test(
    biz_id int, 
    active int,
    biz_id_active int as 
      (case active when 0 then null else biz_id end) 
      unique
 );
 --works
 insert into test(biz_id, active) values(1, 0);
 insert into test(biz_id, active) values(1, 0);
 insert into test(biz_id, active) values(2, 1);
 --fails
 insert into test(biz_id, active) values(2, 1);