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?

有帮助吗?

解决方案

It's possible with a partial unique index:

create unique index uidx on tablename(force_display) where force_display='Y';
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top