I am designing a oracle database for Timesheet application. I am wondering if it is really necessary to have the foreign key constraints on tables (Master and Child).
As we know that theoretically it is good to have a proper referential integrity on tables but do we really need them?
I heard that foreign keys make the database work extra on every DML operation because it has to check FK consistency. This can reduce the performance. But on the other side it can be helpful in the situation where the primary key has been deleted before inserting a new row in the child table.
Performance is a main issue in the timesheet application and there will be about 250 people filling up their timesheets at the end of the month (possibly at the same time).
If i don’t have a foreign key constraint on table then do i have to check it first (in stored procedure) if the primary key exists in the master table before inserting a new record in the child table each time?
Added: In the past, i have worked with many experience oracle database developer and we never used the foreign key constraints on tables.
I’d say develop the application with foreign key constraints in place, then measure the performance, and if performance is an issue, measure the difference between the DB with FK constraints and without, and if they prove to be a performance issue, consider eliminating them.
It is unlikely that you’ll find that they are the source of any performance issues, and I wouldn’t recommend omitting them entirely from the outset on the guess that it will lead to better performance.
You don’t need them, in the same way that you don’t need to validate input, wear safety belts, etc.