I am not able to solve the following situation, related to a TRIGGER called PERSON_BU
The table tPerson was filled in the past with 'old' data from a Spreadsheet.
At the time there were no TRIGGER BEFORE INSERT and TRIGGER BEFORE UPDATE introduced.
The User came accross the following situation:
There are now 2 Persons in the DataBase with the same Surname and DOB.
One Person was imported comes from the SpreadSheet.
The new Person was added to the table tPerson in the DataBase.
Sometime after the new Person was added, both TRIGGERS were introduced.
The reason for the TRIGGER BEFORE INSERT is to help the User to confirm that a Person in the DataBase only appears once.
The reason for the TRIGGER BEFORE UPDATE is to help the User to identify if the potential update of the records of a Person not lead to duplicate records of the same Person.
When information is entered in the DataBase, it is done by hand.
Mistakes are made, handwriting can be difficult to decipher.
Therefore a Person can indeed be in the DataBase more than once.
Because of the fact that a lot of persons do provide their personal information on a regular basis, it is possible that the latest information confirms a multi emtry of the same person.
The User has a process in place to update/merge the multiple records into one unique record.
The principle is simple.
By introducing a Boolean to the different tables, the User can simply confirm that this is the correct record that needs to be updated.
It is only for the table tPerson of utmost importance that the Person is UNIQUE.
Nowadays, there are multiple TRIGGERS in place to help the User to identify potential duplication.
Addresses, Surnames, GivenNames, and Nicknames can change.
However, PhoneNumbers and EmailAddresses likely way less frequent.
For all of these parts there are TRIGGERS in place.
Therefore the chance that there is duplication is minimized.
It turned out that of one Person the records needed to be updated in tPerson.
The TRIGGER BEFORE UPDATE PERSON_BU identifies that there is a record that is identical, based on Surname and DOB, and therefore fires.
The User can 'Check' the record, and whene there is just one entry in the table, the User can update and confirm the information, if needed by a second party, and remove the 'Check'.
However this TRIGGER does NOT work with duplicate information, in this case Surname and DOB.
I can not figure out how to solve the issue.
Can someone please provide me some guidance?
Kind regards,
Dream
Code: Select all
CREATE TRIGGER PUBLIC.PERSON_BU BEFORE UPDATE ON PUBLIC."tPerson"
REFERENCING NEW ROW AS NEWROW FOR EACH ROW
BEGIN ATOMIC
IF EXISTS
(
SELECT
"tPerson"."Surname",
"tPerson"."GivenName",
"tPerson"."Nickname",
"tPerson"."MiddleInitial(s)",
"tPerson"."DateOfBirth"
FROM
PUBLIC."tPerson"
WHERE
(
(
"tPerson"."Surname" = NEWROW."Surname" AND
"tPerson"."DateOfBirth" = NEWROW."DateOfBirth"
) OR
(
"tPerson"."Nickname" = NEWROW."Nickname" AND
"tPerson"."DateOfBirth" = NEWROW."DateOfBirth"
) OR
(
"tPerson"."GivenName" = NEWROW."GivenName" AND
"tPerson"."DateOfBirth" = NEWROW."DateOfBirth"
)
) AND
"tPerson"."Check" = NEWROW."Check"
)
THEN SIGNAL SQLSTATE'45000'SET MESSAGE_TEXT = 'There appears to be a similar Person already recorded. Please verify the Existing entry!';
END IF;
ENDCode: Select all
CREATE TRIGGER PUBLIC.PERSON_BI BEFORE INSERT ON PUBLIC."tPerson"
REFERENCING NEW ROW AS NEWROW FOR EACH ROW
BEGIN ATOMIC
IF EXISTS
(
SELECT
"tPerson"."Surname",
"tPerson"."GivenName",
"tPerson"."Nickname",
"tPerson"."MiddleInitial(s)",
"tPerson"."DateOfBirth"
FROM
PUBLIC."tPerson"
WHERE
(
"tPerson"."Surname"=NEWROW."Surname" AND
(
"tPerson"."DateOfBirth"=NEWROW."DateOfBirth" OR
"tPerson"."GivenName"=NEWROW."GivenName" OR
"tPerson"."GivenName"=NEWROW."Nickname" OR
"tPerson"."Nickname"=NEWROW."GivenName" OR
"tPerson"."Nickname"=NEWROW."Nickname" OR
"tPerson"."MiddleInitial(s)"=NEWROW."MiddleInitial(s)"
) AND
"tPerson"."Check" = FALSE
)
)
THEN SIGNAL SQLSTATE'45000'SET MESSAGE_TEXT='There appears to be a similar Person already recorded. Please verify the Existing entry!';
END IF;
ENDClosed and opened a new related thread