Overview
This function deletes an employee record from thetab_emplea table based on the employee ID. Use with caution as this operation is permanent and may be affected by referential integrity constraints.
Function Signature
Parameters
Employee ID to delete. This identifies the specific employee record to remove from the database.
Return Type
VOID - This function does not return a value. It performs a DELETE operation.
Business Logic
- Simple Deletion: Removes the employee record matching the provided ID
- Referential Integrity: May fail if the employee has related records in other tables (e.g.,
tab_novedades,tab_nomina) - Silent Success: If the employee ID does not exist, the function completes without error but no records are deleted
- No Soft Delete: This is a hard delete operation; the record is permanently removed
Usage Example
Referential Integrity Considerations
Before deleting an employee, you may need to:-
Check for Dependencies: Verify if the employee has related records
-
Clean Up Related Records: Delete or update dependent records first
Error Handling
If the employee has related records protected by foreign key constraints, the function will raise a PostgreSQL error:- Delete the related records first
- Use CASCADE delete (if configured on the foreign key)
- Keep the employee record and mark it as inactive (if your schema supports this)
Best Practices
- Backup First: Always backup data before performing delete operations
- Use Transactions: Wrap delete operations in transactions to allow rollback if needed
- Audit Trail: Consider logging deletions for compliance and audit purposes
- Archive Instead: For historical data integrity, consider archiving employees to a separate table instead of deleting
Transaction Example
Source
Location:~/workspace/source/func/emplea/fun_delete_emplea.sql:8
Author: Camilo SuarezDate: 24/03/2025