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

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -