Forum Moderators: coopster
Is it better to have one recordset with all of the items that you would need in a page? Or, is it better to have multiple recordsets that focus on the specific tasks?
Here's an example. I have a page that both shows records from a timesheet database and at the bottom of the table is a form to update the required fields. I also am calculating the SUM of the total hours for the project through a recordset. Should each of those elements require their own recordset?
Let me know if you need a little more clarification.
Thanks in advance,
Cgallent
When I build a complex page that uses a database in different ways, should I try and get one "master" recordset that has "everything"? Or, several smaller, more concise recordsets?
Thanks.
Here's an example. I have a page that both shows records from a timesheet database and at the bottom of the table is a form to update the required fields. I also am calculating the SUM of the total hours for the project through a recordset. Should each of those elements require their own recordset?
Fields (columns) required:
==========================
Employee
Date
Hours_Worked
Project_ID
Description
Total_Hours
If you were to make this a single file (table) or "recordset", it might end up looking something like this:
Employee Date Hours_Worked Project_ID Description Total_Hours
======== ==== ============ ========== =========== ===========
Bill.....9/23............3.AAA1234567.WebmasterWW...........3
Bill.....9/24............1.AAA1234567.WebmasterWW...........4
Bill.....9/25............5.AAA1234567.WebmasterWW...........9
Bill.....9/26............3.AAA1234567.WebmasterWW..........12
Bill.....9/27............3.AAA1234567.WebmasterWW..........15
Timesheet table:
==========================
Employee
Date
Hours_Worked
Project_ID
Project table:
==========================
Project_ID
Description
Calculated data (not stored, but programmatically displayed upon request):
==========================
Total_Hours
Timesheet Data:
Employee Date Hours_Worked Project_ID
======== ==== ============ ==========
Bill.....9/23............3.AAA1234567
Bill.....9/24............1.AAA1234567
Bill.....9/25............5.AAA1234567
Bill.....9/26............3.AAA1234567
Bill.....9/27............3.AAA1234567
Project data:
Project_ID Description
========== ===========
AAA1234567...WebmasterWW
SELECT Employee, Project_ID, Description, SUM(Hours_Worked)
AS Total_Hours FROM Timesheet, Project WHERE
Timesheet.Project_ID = Project.Project_ID AND
Project_ID = 'AAA1234567';
Employee Project_ID Description Total_Hours
======== ========== =========== ===========
Bill.....AAA1234567.WebmasterWW..........15
And that, my friend is database normalization at it's simplest level. A quick search on Google or other development sites on "database normalization" or "relational database development" should produce some better tutorials.
Regards, coopster
If so then I always try to minimize the number of queries per page since each one adds overhead and server roundtrips (ie slower).
If I missed the mark and you were really asking about DB Design and Normalization simply ignore this comment :)
daisho.
Half dozen of one, half-dozen of the other. I think it ultimately comes down to personal preference (but you have opened up one of programmers favorite debates here). Watch this thread grow now ;)
Why do multiple queries if one will suffice. As I loop through the rows reading them into an array why not just sort them into multiple arrays right away?
Multiple db queries just because its easier is pretty much a waste of resources. One complex query can usually get all of the data you need on any given page.
At some point the query will start hogging process and then you need to either rework the query or split it but every case is unique.
I have cases where the queries can be written as one but the processing power needed is ridiculous. These pages ended up having between 2 and 7 queries each and is much faster.
As I said each case needs to be assessed individually. There are exceptions to every rule but....
less queries == faster
thats the rule ;)