i want to do for a table something like this.
I have two tables one with a foreign key(id) and second table where i hold data that coresponds to the first table.
My problem is that for each entry i might have one or two even more groups that belongs too.
Is it posible to do something like this:
table1 – id(foreign key) table2 – entry1 – table1.id1, table1.id2
And if it is posible can you explain how should i do?
CREATE TABLE IF NOT EXISTS `network`.`dbo.networkNodes` (
`nodeId` INT(11) NOT NULL AUTO_INCREMENT ,
`nodeName` VARCHAR(45) NULL ,
PRIMARY KEY (`nodeId`) )
ENGINE = InnoDB
CREATE TABLE IF NOT EXISTS `network`.`dbo.networkIps` (
`networkIpId` INT(11) NOT NULL AUTO_INCREMENT ,
`nodeId` INT(11) NULL ,
`networkIp` INT(20) NULL ,
PRIMARY KEY (`networkIpId`) )
ENGINE = InnoDB
I think you’re asking for either a many-to-many relationship, or multiple, defined one-to-many relationships, so it depends on the use.
A many-to-many relationship would actually require an intermediate table, containing an ‘id’ field pointing to each of the two tables:
If you would rather add multiple one-to-many relationships, the specific relationship ‘reason’ should be contained in the name of the foreign key.