I think this architecture should solve your problem.
I didn’t put all the VPN fields but you can do it yourself.
If you need the code that generates these tables, see below:
CREATE SCHEMA IF NOT EXISTS `mydb` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci ;
USE `mydb` ;
-- -----------------------------------------------------
-- Table `mydb`.`PARCEIRO`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `mydb`.`PARCEIRO` (
`pk_parceiro` INT NOT NULL AUTO_INCREMENT,
`nome` VARCHAR(45) NULL,
`cpf` VARCHAR(45) NULL,
`RG` VARCHAR(45) NULL,
`E-mail` VARCHAR(45) NULL,
`outrosCampos` VARCHAR(45) NULL,
PRIMARY KEY (`pk_parceiro`))
ENGINE = InnoDB;
-- -----------------------------------------------------
-- Table `mydb`.`USER`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `mydb`.`USER` (
`pk_user` INT NOT NULL AUTO_INCREMENT,
`pk_father` INT NULL,
`Name` VARCHAR(45) NULL,
`outrosCampos` VARCHAR(45) NULL,
PRIMARY KEY (`pk_user`))
ENGINE = InnoDB;
-- -----------------------------------------------------
-- Table `mydb`.`USER_PARCEIROS`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `mydb`.`USER_PARCEIROS` (
`fk_user` INT NOT NULL,
`fk_parceiro` INT NOT NULL,
`outrosCampos` VARCHAR(45) NULL,
PRIMARY KEY (`fk_user`, `fk_parceiro`),
INDEX `fkp_idx` (`fk_parceiro` ASC),
CONSTRAINT `fku`
FOREIGN KEY (`fk_user`)
REFERENCES `mydb`.`USER` (`pk_user`)
ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT `fkp`
FOREIGN KEY (`fk_parceiro`)
REFERENCES `mydb`.`PARCEIRO` (`pk_parceiro`)
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB;
-- -----------------------------------------------------
-- Table `mydb`.`vpnCode_Parc`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `mydb`.`vpnCode_Parc` (
`pk_vpnCOde` INT NOT NULL AUTO_INCREMENT,
`vpnCode` VARCHAR(450) NOT NULL,
`fkParceiro` INT NOT NULL,
`outrosCampos` VARCHAR(45) NULL,
PRIMARY KEY (`pk_vpnCOde`),
INDEX `fkkpar_idx` (`fkParceiro` ASC),
CONSTRAINT `fkkpar`
FOREIGN KEY (`fkParceiro`)
REFERENCES `mydb`.`PARCEIRO` (`pk_parceiro`)
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB;
If a user can only have one partner and this can be associated with multiple users then the model looks like this:
The USER x PARTNER ratio is 1 to 1 or 1 for many?
– Reginaldo Rigo
Each USER may have only one PARTNER, but each PARTNER may have several USERS... That is, 1 to 1
– Cesar Augusto
I think you need a table of USERS, one of PARTNERS, one of CHAVES_VPN, one of USUARIO_PARCEIRO, one of PARCEIROS_USUARIOS and CHAVES_PARCEIROS.
– Reginaldo Rigo