правильно спроектировал ?
CREATE TABLE user (
user_id INT NOT NULL AUTO_INCREMENT,
email_id INT NOT NULL,
first_name TINYTEXT NOT NULL,
PRIMARY KEY(id),
UNIQUE KEY(email_id),
CONSTRAINT user FOREIGN KEY (email_id) REFERENCES user_email (user_email_id) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
CREATE TABLE user_email (
user_email_id INT NOT NULL AUTO_INCREMENT,
user_id INT NOT NULL
email TINYTEXT NOT NULL,
PRIMARY KEY(user_email_id),
UNIQUE KEY(user_id),
CONSTRAINT user_email FOREIGN KEY (user_id) REFERENCES user (user_id) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
Один ко многим должно быть
Обсуждают сегодня