given the following sample table structure is there a way to add to a unique constraint to insure uniqueness for (GUID, 'Y') combination?
Application logic - update by guid
generates a new version with same guid
but new luid
; and previous goes inactive('Y'->'N')
GUID - external id
LUID - internal id
create table id_active(
"GUID" RAW(16) NOT NULL,
"LUID" RAW(16) NOT NULL,
"IS_ACTIVE" char(1) NOT NULL CHECK ( "IS_ACTIVE" IN ('Y', 'N')),
PRIMARY KEY ("GUID", "LUID"),
--unique constraint goes here
You can create a unique function-based index and leverage the fact that Oracle does not index NULL values in b-tree indexes.
CREATE UNIQUE INDEX one_active_guid
ON table_name( (CASE WHEN is_active = 'Y'
THEN guid
ELSE null
END) );
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With