Answer the question
In order to leave comments, you need to log in
How to merge tables correctly?
It is necessary to create two plates: department, users. When displaying a person, information about his department should be displayed. And when outputting a department, information about the employees in that department.
CREATE TABLE Users
(
Id INT PRIMARY KEY AUTO_INCREMENT,
DepartmentId INT,
Age INT,
FirstName VARCHAR(20) NOT NULL,
LastName VARCHAR(20) NOT NULL,
Phone VARCHAR(20) NOT NULL UNIQUE,
FOREIGN KEY (DepartmentId) REFERENCES Departments (id)
);
CREATE TABLE Departments
(
Id INT PRIMARY KEY AUTO_INCREMENT,
UserId INT,
DepartmentName VARCHAR(20) NOT NULL,
FOREIGN KEY (UserId) REFERENCES Users (Id)
);
Answer the question
In order to leave comments, you need to log in
first create the Departments table and then refer to it in the foreign key.
but since you are trying to implement cyclic foreign keys, I inform you that this is not possible. and what's more, it's not true. there are even DBMS that will write about it explicitly in the error text.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question