Например, вы можете сначала вставить данные в таблицу "department" следующим образом:
INSERT INTO Department (Title, Address, ContactInformation)
VALUES ('Отдел 1', 'Адрес 1', 'Контактная информация 1');
Затем, после успешной вставки данных в таблицу "department", вы можете вставить данные в таблицу "trainingevent", учитывая существующие значения внешнего ключа:
INSERT INTO TrainingEvent (Title, Topic, Duration, StartDate, Description, ID_Department, ID_EventType, ID_Instructor, ID_TrainingProgram)
VALUES ('Событие 1', 'Тема 1', '01:30:00', '2022-01-01', 'Описание 1', 1, 1, 1, 1);
Повторите этот процесс для всех таблиц, чтобы убедиться, что вставка данных происходит в правильном порядке и учитывает связи между таблицами.
ID_Employee INT NOT NULL GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
LastName VARCHAR(100) NOT NULL,
FirstName VARCHAR(100) NOT NULL,
MiddleName VARCHAR(100),
Positions VARCHAR(100) NOT NULL,
DateOfBirth DATE NOT NULL,
ContactInformation VARCHAR(100) NOT NULL,
ID_EmployeeStatus INT NOT NULL REFERENCES EmployeeStatus (ID_EmployeeStatus)
);
CREATE TABLE IF NOT EXISTS Department (
ID_Department INT NOT NULL GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
Title VARCHAR(100) NOT NULL,
Address VARCHAR(100) NOT NULL,
ContactInformation VARCHAR(100) NOT NULL
);
CREATE TABLE IF NOT EXISTS EventType (
ID_EventType INT NOT NULL GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
Title VARCHAR(100) NOT NULL
);
CREATE TABLE IF NOT EXISTS Instructor (
ID_Instructor INT NOT NULL GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
FullName VARCHAR(100) NOT NULL,
Positions VARCHAR(100) NOT NULL,
ContactInformation VARCHAR(100) NOT NULL
);
CREATE TABLE IF NOT EXISTS TrainingProgram (
ID_TrainingProgram INT NOT NULL GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
Title VARCHAR(100),
Description TEXT NOT NULL
);
CREATE TABLE IF NOT EXISTS TrainingEvent (
ID_TrainingEvent INT NOT NULL GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
Title VARCHAR(100) NOT NULL,
Topic VARCHAR(100) NOT NULL,
Duration TIME NOT NULL,
StartDate DATE NOT NULL,
Description VARCHAR(100) NOT NULL,
ID_Department INT NOT NULL REFERENCES Department (ID_Department),
ID_EventType INT NOT NULL REFERENCES EventType (ID_EventType),
ID_Instructor INT NOT NULL REFERENCES Instructor (ID_Instructor),
ID_TrainingProgram INT NOT NULL REFERENCES TrainingProgram (ID_TrainingProgram)
);
CREATE TABLE IF NOT EXISTS EmployeeTrainingEvent (
ID_EmployeeTrainingEvent INT NOT NULL GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
ID_Employee INT NOT NULL REFERENCES Employee (ID_Employee),
ID_TrainingEvent INT NOT NULL REFERENCES TrainingEvent (ID_TrainingEvent),
ID_TrainingEvaluation INT NOT NULL REFERENCES TrainingEvaluation (ID_TrainingEvaluation),
DateOfParticipation DATE NOT NULL
);
CREATE TABLE IF NOT EXISTS TrainingEvaluation (
ID_TrainingEvaluation INT NOT NULL GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
Evaluation INT NOT NULL,
Commen TEXT NOT NULL,
DateOfEvaluation DATE NOT NULL
);
CREATE TABLE IF NOT EXISTS Certificate (
ID_Certificate INT NOT NULL GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
Title VARCHAR(100) NOT NULL,
DateOfIssue DATE NOT NULL,
ID_EmployeeTrainingEvent INT NOT NULL REFERENCES EmployeeTrainingEvent (ID_EmployeeTrainingEvent)
);
CREATE TABLE IF NOT EXISTS EmployeeStatus (
ID_EmployeeStatus INT NOT NULL GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
StatusName VARCHAR(100) NOT NULL
);
сама заполняю вылезает ошибка ERROR: Ключ (id_department)=(1) отсутствует в таблице "department".INSERT или UPDATE в таблице "trainingevent" нарушает ограничение внешнего ключа "trainingevent_id_department_fkey"
ОШИБКА: INSERT или UPDATE в таблице "trainingevent" нарушает ограничение внешнего ключа "trainingevent_id_department_fkey"
SQL-состояние: 23503
Подробности: Ключ (id_department)=(1) отсутствует в таблице "department".