How to have a single unique value in a column while other values are not unique?

StackOverflow https://stackoverflow.com/questions/22821228

  •  26-06-2023
  •  | 
  •  

Pergunta

I have a table with a column called force_display. This column is 1 character long and takes either a Y or N. I want to be able to enter as many N as I want but have a constraint where a Y can only exists once in that table. Does anyone know how to achieve this or is it not possible?

Foi útil?

Solução

It's possible with a partial unique index:

create unique index uidx on tablename(force_display) where force_display='Y';
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top