Hi,
We are a University, and as such almost our entire user base (c 50,000) changes every 3 years.
To fight this we have been running a script annually to delete users.
Basically we mark all users who have left with status = "0" and run the script twice annually against the database.
This script has run fine for years but for some reason this time we are getting a constraint error and can't figure out why as we haven't changed anything.
Before I log this as a support call, does anyone have any ideas?
Here's the script and error:
CREATE OR REPLACE PROCEDURE LD_BTO."DELETE_ALL_DEAD_USERS" IS
v_guid raw(16);
v_count int;
CURSOR
UserCursor
IS
SELECT
tu.tps_guid
FROM
tps_user tu
,tps_user_type tut
WHERE
tu.TPS_USER_TYPE_GUID = tut.TPS_GUID
AND
tut.tps_name = 'EndUser'
AND
(tu.USR_STATUS = 'Dead' OR tu.USR_STATUS = '0');
BEGIN
v_count := 0;
FOR UserCursor_REC IN UserCursor LOOP
v_guid := UserCursor_REC.tps_guid;
v_count := v_count + 1;
UPDATE pm_process
SET PM_DESCRIPTION = 'Deleted User information: '||(select TPS_NAME||' - '||USR_EMPLOYEETYPE||' - '||USR_USERNAME||' | '||chr(13) from tps_user where TPS_GUID = v_guid)||PM_DESCRIPTION
WHERE pm_raise_user_guid = v_guid;
COMMIT;
UPDATE pm_process
SET pm_raise_user_guid = (select tps_guid from tps_user where tps_title = 'DeletedUser')
WHERE pm_raise_user_guid = v_guid;
COMMIT;
BEGIN
-- delete links to the end users
DELETE /*+ hint index(TPS_USER_ID) */ FROM tps_user_role WHERE tps_user_id = v_guid;
DELETE /*+ hint index(TPS_USER_ID) */ FROM tps_user_group WHERE tps_user_id = v_guid;
DELETE FROM tps_user_message_recipient WHERE tps_user_guid = v_guid;
DELETE FROM cf_user_config_item WHERE cf_user_guid = v_guid;
DELETE FROM tps_application_user_setting WHERE tps_user_guid = v_guid;
DELETE FROM tps_application_mru WHERE tps_user_guid = v_guid;
DELETE FROM tps_user_query WHERE tps_user_guid = v_guid;
DELETE FROM tps_user_network_login WHERE tps_user_guid = v_guid;
DELETE FROM tps_user_session WHERE tps_user_guid = v_guid;
-- delete the end users' passwords
UPDATE tps_user SET tps_password_id = NULL WHERE tps_guid = v_guid;
DELETE FROM tps_password WHERE tps_guid = v_guid;
-- delete the end users
DELETE FROM tps_end_user WHERE tps_guid = v_guid;
DELETE FROM tps_user
WHERE tps_guid = v_guid
AND (USR_STATUS = 'Dead' OR USR_STATUS = '0');
EXCEPTION WHEN OTHERS THEN
ROLLBACK;
v_count := 0;
END;
IF v_count >= 5 THEN
COMMIT;
v_count := 0;
END IF;
END LOOP;
COMMIT;
-- delete audit trail for End User
DELETE FROM
tps_audit_trail
WHERE
tps_class_type_id = ( SELECT md_guid
FROM md_class_type
WHERE md_client_class = 'Touchpaper.ClientClasses.SystemManagement.EndUser');
COMMIT;
END;
And the error is: Others :-2292-ORA-02292: integrity constraint (LD_BTO.FKEY$PM_PROCESS$CRUSR) violated - child record found-v_count:=1
Thanks.