database - SQL one-to-many -
i trying build sql schema system have channels
, each id
, , 1 or more fixtures
. having difficulty finding way implement one-to-many mapping. (i.e. 1 channel
many fixtures
). using h2 database engine.
i cannot have table :
id | fixture ----|---------- 1 | 1 1 | 2 2 | 3 create table channel( id int not null primary key, fixture int not null );
... primary key
id
must unique
.
similarly, cannot map follows:
create table channel( id int not null primary key, f_set int not null references fixtures(f_set) ); create table fixtures( id int not null primary key, f_set int not null );
... required f_set
unique
i implementing follows:
create table channel( id int not null primary key, f_set int not null references fixture_set(id) ); create table fixtures( id int not null primary key, f_set int not null references fixture_set(id) ); create table fixture_set( id int not null primary key );
... means can have channel
fixture_set
not have assigned fixtures
(not ideal).
i wondering if had suggestions how may approach (or understanding wrong). thanks
"one-to-many" means many items (may) reference 1 item. if it's 1 channel many fixtures, fixtures should reference channels, not other way round, means reference column should in fixtures
table:
create table channel( id int not null primary key ); create table fixtures( id int not null primary key, channel_id int not null foreign key references channel (id) );
Comments
Post a Comment