sql - Table in Derby with complex primary key -


is possible have primary key composed of foreign keys fk1, fk2, fk3

where:

  • fk1 should never null

  • fk2 , fk3 can null

i have following sql:

create table role_mappings (        role_name            varchar(64)       not null,        nested_role_name     varchar(64)       default null,        privilege_name       varchar(64)       default null,        primary key (role_name, nested_role_name, privilege_name),        constraint fk_access_roles_rm_1 foreign key (role_name) references access_roles (role_name),        constraint fk_access_privileges foreign key (privilege_name) references access_privileges(privilege_name),        constraint fk_access_roles_rm_2 foreign key (nested_role_name) references access_roles(role_name) ); 

when insert null nested_role_name or privilege_name, get:

column 'nested_role_name'  cannot accept null value. 

what's proper way of doing this?

primary key values must unique. if allow null values these fields makeup primary key run trouble non-uniqueness. avoid using null values advice.


Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -