sql - Oracle Problems with Composite Keys -


bit confusing question here: trying create composite fk composite pk. i'll show tables in question i'm having problems with;

create table weapons ( weapon_id varchar(10) not null, weapon_name varchar(30), range_in_meters int, maximum_number_of_uses int, damage_factor int, cost int, primary key(weapon_id));  create table weaponinventory ( inventory_id varchar(30) not null, weaponinventory_id varchar(10) not null, weapon_id varchar(10) references weapons(weapon_id) not null, primary key(inventory_id, weaponinventory_id));  create table avatars ( avatar_id varchar(10) not null, avatar_name varchar(30), ava_dob date, age varchar(30), gender varchar(30), strength_indicated int, hoard int, avatar_level varchar(30), skill varchar(30), original_owner varchar(30), family_id varchar(10) not null, species_id varchar(10) not null, inventory_id varchar(30) not null, weapon_id varchar(10) not null, player_id varchar(10) not null, primary key (avatar_id), foreign key (inventory_id, weapon_id) references weaponinventory (inventory_id, weapon_id)); 

in table avatars, have been trying create foreign key i'm having no luck. have errors such as:

ora-02270: no matching unique or primary key column-list

and:

ora-02270: no matching unique or primary key column-list

any appreciated! keep getting confused , ending in same place! (:

i think planned reference column weaponinventory_id (instead of weapon_id) in table weaponinventory:

foreign key (inventory_id, weapon_id) references weaponinventory (inventory_id, weaponinventory_id) -- see here 

note weapon_id not part of pk in weaponinventory:

create table weaponinventory (   inventory_id varchar(30) not null,   weaponinventory_id varchar(10) not null,   weapon_id varchar(10) references weapons(weapon_id) not null,   primary key(inventory_id, weaponinventory_id) -- weapon_id not part of pk ); 

check fiddle.


Comments

Popular posts from this blog

google chrome - Developer tools - How to inspect the elements which are added momentarily (by JQuery)? -

angularjs - Showing an empty as first option in select tag -

php - Cloud9 cloud IDE and CakePHP -