0
I am trying to implement a 1:1 relationship between the Employee table and the User table, in Mysql Workbench, but when generating the Diagram I see that the relationship always remains at 1:n, even with the strainCont UNIQUE in the foreign key.
CREATE TABLE `funcionario` (
`id` int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY,
`nome` varchar(50) NOT NULL,
`cpf` varchar(50) NOT NULL UNIQUE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE `usuario` (
`id` int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY,
`nome` varchar(50) NOT NULL UNIQUE,
`senha` varchar(8) NOT NULL,
`nivel` enum('1','2','3') NOT NULL,
`datacadastro` DATE NOT NULL,
`id_funcionario` int(11) NOT NULL UNIQUE,
INDEX `fk_id_funcionario` (`id_funcionario` ASC)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
alter table `usuario`
add foreign key (`id_funcionario`) references `funcionario`(`id`);
How can I specify that for this case the relationship should be 1:1?
If the relationship is 1:1, why don’t you join the two tables?
– Thiago Magalhães
I thought to unite, but will be extreme minority employees who will have registered users, soon will remain many null fields in a unified table.
– Raphael
If the user foreign key is
UNIQUE
and she’sNOT NULL
, there’s no way the table is 1:n.– Thiago Magalhães
I also thought this way, but when I do the "Reverse Engineer" to generate the diagram, it displays the relationship as if it were 1:n
– Raphael
See if that reply help you.
– Thiago Magalhães