Implementing a 1 to many relationship with SQLite

Posted by Patrick on Stack Overflow See other posts from Stack Overflow or by Patrick
Published on 2010-05-30T10:35:27Z Indexed on 2010/05/30 10:42 UTC
Read the original article Hit count: 293

Filed under:
|
|

I have the following schema implemented successfully in my application. The application connects desk unit channels to IO unit channels. The DeskUnits and IOUnits tables are basically just a list of desk/IO units and the number of channels on each. For example a desk could be 4 or 12 channel.

CREATE TABLE DeskUnits (Name TEXT, NumChannels NUMERIC);
CREATE TABLE IOUnits (Name TEXT, NumChannels NUMERIC);

CREATE TABLE RoutingTable (DeskUnitName TEXT, DeskUnitChannel NUMERIC, IOUnitName TEXT, IOUnitChannel NUMERIC);

The RoutingTable 'table' then connects each DeskUnit channel to an IOUnit channel. For example the DeskUnit called "Desk1" channel 1 may route to IOunit name "IOUnit1" channel 2, etc.

So far I hope this is pretty straightforward and understandable. The problem is, however, this is a strictly 1 to 1 relationship. Any DeskUnit channel can route to only 1 IOUnit channel.

Now, I need to implement a 1 to many relationship. Where any DeskUnit channel can connect to multiple IOUnit channels. I realise I may have to rearrange the tables completely, but I am not sure the best way to go about this.

I am fairly new to SQLite and databases in general so any help would be appreciated.

Thanks

Patrick

© Stack Overflow or respective owner

Related posts about sql

Related posts about sqlite