I am currently building a database for different sensors and now i have to create assets. By asset, i mean group of sensors like in a room or a group of sensors of the same type.
The thing is : 1 sensor can be in Asset A (Machine 1) and Asset B (Machine 2). We can consider it to be a temperature sensor in a room containing the 2 machines.
What i want to do, is to link that sensor to the 2 assets and i don't really see how to do it and this is where i need some help.
In my database, i can give an Asset_ID, and going in the Asset_Table, i can link my sensor to ONE machine using the Asset_ID.
So, how can i link the sensor to 2 Asset_ID, so it will be associated with the 2 machines in my database
I hope this is a bit clear !
You want an AssetMachines
table:
create table AssetMachines (
AssetMachine_Id serial primary key,
Asset_Id int references assets(asset_id),
Machine_Id int references machines(machine_id),
. . . -- more columns can go here
);
I think the many-to-many relationship is best expressed by
CREATE TABLE assetmachines (
asset_id integer references assets (asset_id),
machine_id integer references machines (machine_id),
PRIMARY KEY (asset_id, machine_id)
);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.