sql - Check if a value appears only once in a column -
i want create table managing versions of parameters...
in table there column of type char lets me know version have use :
create table parameters_version (                 id number not null,                 version number not null,                 date_start date not null,                 date_end date check(date_start <= date_end) not null                 isused char(1) check(isused in ('y','n')) not null,                 constraint parameters_version_version_pk primary key (id),                 constraint parameters_version_version_uk unique (isused) );   how define unique constraint on column isused have single row value 'y' (and others 'n') ?
by way, check constraint on date_end correct ?
oracle doesn't quite support partial or filtered indexes. instead, can use functional index cleverness:
create unique index idx_parametersversion_isused     on parameters_version(case when is_used = 'y' -1 else id end);   that is, when is_used has value other y, primary key used.  when y, constant used, 2 values conflict.
Comments
Post a Comment