Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

The Database Forum


You are currently viewing our The Database Forum as a guest. Please register to participate.
Login



Reply
Need help deciding what tables should be used
Old 06-05-2008, 07:12 AM Need help deciding what tables should be used
drew22299's Avatar
Skilled Talker

Posts: 93
Trades: 0
Hi,

What would be the best way (in terms of the tables needed and how many tables etc) to store licensing information entered into forms (web based or ms forms) by truck drivers? And allow reports to be made.

Any suggestions?
drew22299 is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 06-05-2008, 02:30 PM Re: Need help deciding what tables should be used
Learning Newbie's Avatar
Defies a Status

Latest Blog Post:
Astounding Republican Paranoia
Posts: 5,662
Name: John Alexander
Trades: 0
Well that depends on what licensing information you want to store, and what types of reports you want to make. Without knowing these things, the best answer I can give is 42.
__________________

Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE
Learning Newbie is offline
Reply With Quote
View Public Profile
 
Old 06-05-2008, 03:32 PM Re: Need help deciding what tables should be used
drew22299's Avatar
Skilled Talker

Posts: 93
Trades: 0
The type of data that will be stored includes name and address of driver, when their license was issued, how long they have had their licesnce etc

What is the most efficient way to store this data? Would I have a driver table and then have a corresponding table that stores the license info separatly? And a separate table for addresses? Would I need any joining tables?

Thanks,

Last edited by drew22299; 06-05-2008 at 03:34 PM..
drew22299 is offline
Reply With Quote
View Public Profile
 
Old 06-05-2008, 05:29 PM Re: Need help deciding what tables should be used
Learning Newbie's Avatar
Defies a Status

Latest Blog Post:
Astounding Republican Paranoia
Posts: 5,662
Name: John Alexander
Trades: 0
You're going to think I'm being an, well, it means the same as donkey, but the most efficient way to store data depends on how the data is accessed.

You could use one giant table instead of it sounds like you're considering 3. Now if you found your application editing one field that only corresponds to one functional area (the driver, say, or the license) that would be a bottleneck. There's a cost of having your data split into multiple tables, and it's paid when you join them. There's also a cost in having your data consolidated into single tables, which is paid in making updates, and usually in duplicated data giving you more volume to search through - incurring more physical, disc based IO to find a particular group of records. Optimizing a database for speed and efficiency is mostly about knowing what are the access patterns for the particular collection of data.

Again, I know that sounds like I'm trying to be unhelpful, but it's the truth. On the other hand, there's a concept of premature optimization. Most people will also say you're better off structuring the information in a way that makes sense, logically, and is easy to work with. Then, add speed improvements, if you find you really need to. At that point, you'll know exactly what part needs improvement, and why.
__________________

Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE
Learning Newbie is offline
Reply With Quote
View Public Profile
 
Old 06-05-2008, 10:53 PM Re: Need help deciding what tables should be used
nyef's Avatar
Ultra Talker

Posts: 265
Name: Lucas
Trades: 0
For simplicity's sake, I would start with one table since it all has a one-to-one relationship. Each driver only has one license. Unless you're wanting to keep past license information for drivers, then you would have to have multiple tables. Assuming you only need to keep current license information, just put it all in one table.

You won't suffer performance-wise until and unless you get to many thousands of records. Once you have thousands of drivers in your database and if things start slowing down, you can then decide based on how people are already using the database (the reports being run, etc) which data to split off into separate tables and which functions to build into stored procedures, etc etc.
__________________
~nyef

Please login or register to view this content. Registration is FREE
nyef is offline
Reply With Quote
View Public Profile Visit nyef's homepage!
 
Old 06-06-2008, 10:03 AM Re: Need help deciding what tables should be used
drew22299's Avatar
Skilled Talker

Posts: 93
Trades: 0
Thanks again for the excellent comments Learning Newbie, your comment was informative and is helpful.

nyef, I would like to try and make the database design complex, this isn't for anything in particular, I just want to experiment and actually make a complicated database that conists of more than two tables lol

I have thought about other information that could be included, could you guys tell me how you would do it? I need other people's perspectives on this, (people with more experience in database design)

The system needs to store
driver name, address etc
license information
information on previous licenses
driving convictions
payments/fees

I'm guessing I could have tables for all of the above? A driver can have many payments, and convictions - one to many?
drew22299 is offline
Reply With Quote
View Public Profile
 
Old 06-06-2008, 12:29 PM Re: Need help deciding what tables should be used
nyef's Avatar
Ultra Talker

Posts: 265
Name: Lucas
Trades: 0
Table: t_driver
Fields:
id [int(4)]
firstname [varchar(50)]
lastname [varchar(50)]
address1 [varchar(200)]
address2 [varchar(200)]
city [varchar(50)]
state [varchar(2)]
zip [varchar(10)]
licensenum [varchar(50)]
licenseexpire [datetime]

Table: t_license
id [int(4)]
driverid [int(4)]
licensenum [varchar(50)]
licensedate [datetime]
licenseexpire [datetime]
state [varchar(2)]

Table: t_payment
id [int(4)]
driverid [int(4)]
date [datetime]
amount [numeric(9,2)]
description [varchar(200)]

etc etc

I always use a global unique identifier (ID or GID) for each table for indexing and faster loading of specific records. Then when you need to match up the data, you just join on the driverid field on the other tables and the id field on the driver table.

That help?

You can make it as complex as you want... you can even put specific restrictions on certain fields, triggers, etc... But the more restrictions you build into the database, the more time you will have to spend on database management. I prefer to make the database as unrestrictive as possible and let the web app handle all the metadata stuff. Database management is so boring =). I don't even usually bother preventing nulls on fields! Ha
__________________
~nyef

Please login or register to view this content. Registration is FREE
nyef is offline
Reply With Quote
View Public Profile Visit nyef's homepage!
 
Old 06-06-2008, 03:37 PM Re: Need help deciding what tables should be used
drew22299's Avatar
Skilled Talker

Posts: 93
Trades: 0
Thanks nyef that's great you have answered many questions all in one post!

My last question is, where there is a one to many relationship do you need a joining table? Or is that only for many to many relationships?

Thanks,
drew22299 is offline
Reply With Quote
View Public Profile
 
Old 06-06-2008, 05:55 PM Re: Need help deciding what tables should be used
Learning Newbie's Avatar
Defies a Status

Latest Blog Post:
Astounding Republican Paranoia
Posts: 5,662
Name: John Alexander
Trades: 0
You can have a one to many relationship with or without a joining (aka mapping) table. Let's take what you want to do for example, and look at both ways you could do it. We'll use drivers and addresses, including a history of addresses.

We could have a table of drivers which are really people. And a table of addresses. That table would have the city, state, zip code, and all the other address data we're used to. Now, you could add a field to your address table called (something like) DriverID, which would be a foreign key (FK) on the many side of a one to many relationship. Or you could not have that as part of the address, but have an AddressID field in that table, and a third table with DriverID and AddressID - maybe also a start and end date for when that person had that address. How I would decide which of those 2 options to go for, is probably to ask myself if, in the data model I'm building, 2 drivers can ever have the same address? That could be a husband and wife living together, or that could be a guy moving out of his apartment, and someone else moving in. Really, we're asking if it's a one to many or a many to many relationship. In the real world it's many to many, but can you ignore them for the purposes of your application?

Driving convictions would be another one to many. One driver has many convictions. It could be that Sam has none, and Bob has 5. Again, you could just put a DriverID field in the convictions table, which itself might point to a Crimes table. That would let you do a "roll up" and see how many convictions are for running a red light, versus how many are for DUI. In that case, you could think of your convictions table being a mapping table between drivers and crime types, except that it would probably have some other fields like the date, the sentence, and anything else that was useful.
__________________

Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE
Learning Newbie is offline
Reply With Quote
View Public Profile
 
Old 06-07-2008, 03:29 PM Re: Need help deciding what tables should be used
nyef's Avatar
Ultra Talker

Posts: 265
Name: Lucas
Trades: 0
I never use joining/mapping tables except for many-to-many relationships. On one-to-many relationships, just include the primary id of the "one" table as an extra field on the "many" table in addition to the "many" table having it's own primary id field.

t_driver
id
other fields

t_driverlicenseorwhatever
id
driverid
other fields

Then joins are easy:
Code:
select * from t_driverlicense,t_driver 
where t_driverlicense.driverid*=t_driver.id
__________________
~nyef

Please login or register to view this content. Registration is FREE
nyef is offline
Reply With Quote
View Public Profile Visit nyef's homepage!
 
Reply     « Reply to Need help deciding what tables should be used
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.32867 seconds with 12 queries