MySQL Forums
Forum List  »  Newbie

Doubt about foreign keys and primary keys.
Posted by: desconhescido 15l
Date: April 18, 2018 08:29AM

When a foreign key receives a value the columns of the primary key table should get null?

CREATE TABLE `information_people` (
`ID` smallint(6) NOT NULL AUTO_INCREMENT,
`Name` varchar(50) DEFAULT NULL,
`Date_Born` date DEFAULT NULL,
`Address` varchar(100) DEFAULT NULL,
`Telephone` smallint(6) DEFAULT NULL,
`RG` smallint(6) DEFAULT NULL,
`CPF` smallint(6) DEFAULT NULL,
`ID_column1` smallint(6) DEFAULT NULL,
`ID_column2` smallint(6) DEFAULT NULL,
`ID_column3` smallint(6) DEFAULT NULL,
PRIMARY KEY (`ID`),
KEY `fk_ID_Column1` (`ID_Infected`),
KEY `fk_ID_Column2` (`ID_Ifsul`),
KEY `fk_ID_Column3` (`ID_Gym`),
CONSTRAINT `fk_ID_Column1` FOREIGN KEY (`ID_Column1`) REFERENCES `column1` (`ID`) ON DELETE CASCADE ON UPDATE CASCADE,
CONSTRAINT `fk_ID_Column2` FOREIGN KEY (`ID_Column2`) REFERENCES `column2` (`ID`) ON DELETE CASCADE ON UPDATE CASCADE,
CONSTRAINT `fk_ID_Column3` FOREIGN KEY (`ID_Column3`) REFERENCES `column3` (`ID`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8mb4

When I add a row in the information_people table should not to be automatically add a row in the columns of the tables that are primary key of the foreign key columns?
If not, can you do this with the use of the Keys?

Options: ReplyQuote


Subject
Written By
Posted
Doubt about foreign keys and primary keys.
April 18, 2018 08:29AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.