473,396 Members | 1,826 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

One table or three?

MP
context: (vb6 / ado / .mdb / jet4.0 / not using access)

hypothetical problem
say I need to track the properties of boxes.

There are three kinds, cardboard, wood, and sheet metal.

Each box has some common properties, width, depth, height
So one table makes sense to store that....tblBoxes

but...each box type also has properties that only apply to that type...

cardboard...fiber content, IsRecycledBool, etc
wood...species, etc
metal....gageSize, IsGalvanizedBool, etc

so if I have one table, each entry will have lots of nulls for the
properties that don't apply,
and the calling code will have some kind of branching code to decide what
properties to query???

or should I have 3 tables tblCardboardBox, tblWoodBox, tblMetalBox
then the calling code still needs branching code to decide what table to
query but there aren't a bunch of nulls...

is there any argument *against* lots of null values for "not applicable"
fields?
is it easier to make branching code to access different fields versus
different tables?
any suggestions?
Thanks
Mark
Jan 5 '06 #1
11 1599
Per MP:
There are three kinds, cardboard, wood, and sheet metal.

Each box has some common properties, width, depth, height
So one table makes sense to store that....tblBoxes

but...each box type also has properties that only apply to that type...

cardboard...fiber content, IsRecycledBool, etc
wood...species, etc
metal....gageSize, IsGalvanizedBool, etc

so if I have one table, each entry will have lots of nulls for the
properties that don't apply,
and the calling code will have some kind of branching code to decide what
properties to query???

or should I have 3 tables tblCardboardBox, tblWoodBox, tblMetalBox


Or maybe even 4 tables:

tblBox, which contains common info plus three RecordID fields - only one of
which is populated - and points to: tblCardboardBox, tblWoodBox, or
tblMetalBox.

That way, you can query with three joins from tblBox and pick up whatever is
relevant, getting Null values for the tables in which there is no child rec.
--
PeteCresswell
Jan 5 '06 #2
(PeteCresswell) wrote:
Per MP:
There are three kinds, cardboard, wood, and sheet metal.

Each box has some common properties, width, depth, height
So one table makes sense to store that....tblBoxes

but...each box type also has properties that only apply to that type...

cardboard...fiber content, IsRecycledBool, etc
wood...species, etc
metal....gageSize, IsGalvanizedBool, etc

so if I have one table, each entry will have lots of nulls for the
properties that don't apply,
and the calling code will have some kind of branching code to decide what
properties to query???

or should I have 3 tables tblCardboardBox, tblWoodBox, tblMetalBox

Or maybe even 4 tables:

tblBox, which contains common info plus three RecordID fields - only one of
which is populated - and points to: tblCardboardBox, tblWoodBox, or
tblMetalBox.

That way, you can query with three joins from tblBox and pick up whatever is
relevant, getting Null values for the tables in which there is no child rec.


I'd suggest a record ID, the type (Cardboard, Wood or Metal) and the
common fields in one table, the record ID and the proprietary fields in
three other tables.

Stevel
Jan 5 '06 #3
Per Stevel:
I'd suggest a record ID, the type (Cardboard, Wood or Metal) and the
common fields in one table, the record ID and the proprietary fields in
three other tables.


But how would he join to the other three tables simultaneously? Seems like
that would introduce the need for some logic before doing the join.
--
PeteCresswell
Jan 5 '06 #4
Or, how about one table consisting of:
BoxID
Characteristic (lookup to list of possible characteristics such as
IsRecycledBool, etc
species, etc
gageSize, IsGalvanizedBool, etc

and Value e.g.
BoxID Characteristic Value
124 isrecycled T
128 gagesize 12
128 isgalvanized T

I'm not saying it'd be _easy_ to query, but with crosstabs, maybe...

Jan 5 '06 #5
> is there any argument *against* lots of null values for "not applicable"
fields?


Not really. Disk space is nearly free. Records don't actually grow much
with blank fields. I don't know about performance, but if you're
talking about several fields for each type, as opposed to several dozen
fields for each type, I can't imagine there's a measurable performance
hit, and certainly not one that wouldn't be present in many other
queries.

I say put it all in one table.

Jeremy

Jan 5 '06 #6
MP

"Stevel" <stevenlangenaken-at-@hotmail-dot-.com> wrote in message
news:11***************@seven.kulnet.kuleuven.ac.be ...
(PeteCresswell) wrote:
Per MP:
There are three kinds, cardboard, wood, and sheet metal.

Each box has some common properties, width, depth, height
So one table makes sense to store that....tblBoxes

but...each box type also has properties that only apply to that type...

cardboard...fiber content, IsRecycledBool, etc
wood...species, etc
metal....gageSize, IsGalvanizedBool, etc

so if I have one table, each entry will have lots of nulls for the
properties that don't apply,
and the calling code will have some kind of branching code to decide whatproperties to query???

or should I have 3 tables tblCardboardBox, tblWoodBox, tblMetalBox

Or maybe even 4 tables:

tblBox, which contains common info plus three RecordID fields - only one of which is populated - and points to: tblCardboardBox, tblWoodBox, or
tblMetalBox.

That way, you can query with three joins from tblBox and pick up whatever is relevant, getting Null values for the tables in which there is no child

rec.
I'd suggest a record ID, the type (Cardboard, Wood or Metal) and the
common fields in one table, the record ID and the proprietary fields in
three other tables.

Stevel


so maybe 5 tables?
....
common box table
tblBox
fldBoxID PK
fldBoxTypeID FK from tblBoxType
....then fields common to all box types
fldBoxWidth
fldBoxHeight
fldBoxDepth
fldBoxName
....
"lookup table" for types
tblBoxType
fldBoxTypeID PK
fldBoxTypeName (one record for each type)
....
tblBoxCardboard
fldBoxId FK from tblBox
fldBoxFiber
....
tblBoxWood
fldBoxId FK from tblBox
fldBoxSpecies
....
tblBoxMetal
fldBoxId FK from tblBox
fldBoxGage

then to get info on one specific box
(mind you this is my first attempt to learn sql so not sure about these JOIN
clauses)
would this automatically get the records for a particular box regardless of
what type it is?

Select * From tblBox
From tblBox INNER JOIN tblBoxCardboard
ON tblBox.fldBoxID = tblBoxCardboard.fldBoxID
INNER JOIN tblBoxWood
ON tblBox.fldBoxID = tblBoxWood.fldBoxID
INNER JOIN tblBoxMetal
ON tblBox.fldBoxID = tblBoxMetal.fldBoxID

do I understand join correctly that if the fldBoxID does not exist in that
particular table, then no records will be returned.
That would mean I don't need any code to determine before hand what type of
box it is...
since the boxId will only exist in one of the three subtype tables...?

thanks
Mark
Jan 5 '06 #7
Per MP:
That would mean I don't need any code to determine before hand what type of
box it is...
since the boxId will only exist in one of the three subtype tables...?


That's what moved me to do it that way - as opposed to a link table to a single
properties table as Penguin suggested. OTOH, Penguin's method is the most
open-ended, expansion-friendly of the two. You can properties until the cows
come home: all that's needed is a new record in tlkpBoxProperties.

I think mine is easier to code retrieval/presentation-wise, but I wouldn't bet
the mortgage money on that without a little fooling around with skeleton
implementations of each approach.

tlkpBoxType is definitely needed - an omission by Yours Truly.
--
PeteCresswell
Jan 5 '06 #8
MP
"(PeteCresswell)" <x@y.Invalid> wrote in message
news:n6********************************@4ax.com...
Per MP:
That would mean I don't need any code to determine before hand what type ofbox it is...
since the boxId will only exist in one of the three subtype tables...?
That's what moved me to do it that way - as opposed to a link table to a

single properties table as Penguin suggested. OTOH, Penguin's method is the most open-ended, expansion-friendly of the two. You can properties until the cows come home: all that's needed is a new record in tlkpBoxProperties.

I think mine is easier to code retrieval/presentation-wise, but I wouldn't bet the mortgage money on that without a little fooling around with skeleton
implementations of each approach.

tlkpBoxType is definitely needed - an omission by Yours Truly.
--
PeteCresswell


Thanks, I'll study Penguins idea some more to see if I can Grok it!
:-)

Mark

ps, was the join idea even close???
Jan 5 '06 #9
MP
<pe***********@aol.com> wrote in message
news:11*********************@f14g2000cwb.googlegro ups.com...
Or, how about one table consisting of:
BoxID
Characteristic (lookup to list of possible characteristics such as
IsRecycledBool, etc
species, etc
gageSize, IsGalvanizedBool, etc

and Value e.g.
BoxID Characteristic Value
124 isrecycled T
128 gagesize 12
128 isgalvanized T

I'm not saying it'd be _easy_ to query, but with crosstabs, maybe...


Thanks for the response, Penguin

I'm trying to understand it

when you say "BoxID" I thought you meant that would be the PK for tblBox
but since there's more than one entry it can't be.
so the PK would be another field not shown above...is that correct?

if that's the correct interpretation, wouldn't that mean I have another
table to store BoxID as PK?
tblBox
fldBoxID PK
fldBoxDescription

when you say "lookup to list of..." are you referring to a "Lookup table"?
if so, wouldn't I have another table tblCharacteristics?
tblChar
fldCharID PK
fldCharDescription

and then the table you showed above
tblBoxCharacteristics
fldBCID PK
fldBoxID FK from tblBox
fldCharID FK from tblChar
fldCharVal - with constraints to enforce buisness rules????

then say one type of box has 10 characteristics, I would have 10 entries
with same BoxID
is that what you're suggesting???

I'm not sure that's what you were saying because then I'm back to 3 tables.

sorry, I guess I'm not fully understanding the idea you're trying to convey
about only one table.
Can you set me straight?

Thanks
Mark
Jan 6 '06 #10
a late response but just to say there is an example of this sort of thing on the Access web
http://www.mvps.org/access/resources/downloads.htm
look for "one to one"

Jan 6 '06 #11
MP

"polite person" <si*****@ease.com> wrote in message
news:17********************************@4ax.com...
a late response but just to say there is an example of this sort of thing on the Access web http://www.mvps.org/access/resources/downloads.htm
look for "one to one"

Thanks I'll check that out.

Jan 7 '06 #12

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

61
by: Toby Austin | last post by:
I'm trying to replace <table>s with <div>s as much as possible. However, I can't figure out how to do the following… <table> <tr> <td valign="top" width="100%">some data that will...
2
by: Sugapablo | last post by:
Can anyone help me out with some code to change three table cells (<td>) when one is hovered over? I have a calendar grid where each day is made up of three table cells and I want all three to...
9
by: Wang, Jay | last post by:
I try to group several rows in a table into a div and show/hide them by click on a button somewhere with a javascript link. When clicked, the link will toggle the style of the div section's style...
2
by: Thomas T. Thai | last post by:
I would like to select a random record from a group of records so I'd end up with one random record per group: CREATE TABLE randtest ( catnum int, title varchar(32) ); INSERT INTO randtest...
3
by: EJH | last post by:
I have a Database that has three tables. One of the three is just a table that contains three fields and is filled with reference information. One field is 3-Digit(primary key), the next is...
6
by: Marko Mikkonen | last post by:
I'm trying to make code which does something when user clicks a row in a table. I tried a javascript code from JS-Examples.com. It works on Firefox, but not on Internet explorer 7. Here's the code:...
4
by: wrldruler | last post by:
Hello, First, I know it's against "Access Law" to save calculations in a table, but....I want/need to. I currently have sub-totals being calculated inside a form, using DMax, DCount, and...
1
by: bostonguy70 | last post by:
I am not a mysql expert and was trying to find something like this. I have two tables. Comments Table has 3 fields, country, comments and date with NO unique or primary keys Table below...
1
by: =?Utf-8?B?ZnJhbmt5?= | last post by:
Hello, I've created a table that has two rows that are span across three columns. The third row has three columns, each with an image. The last row is also span accross three columns. The span...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.