dbTalk Databases Forums  

Master/detail with one table

comp.databases.informix comp.databases.informix


Discuss Master/detail with one table in the comp.databases.informix forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
loc
 
Posts: n/a

Default Master/detail with one table - 04-16-2012 , 09:03 AM






To keep a database normalized should a one to many relationship always use two tables? The data in the following table is used as a master record, once it's setup it will rarely be changed or have more rows added to it.

create table tab1
(account integer,
field2 char(40))

There will be about 4 unique values for tab1.account and about 3 associatedrows for tab1.field2. Since the data set is so small would it be better to just put it all into one table with two columns rather than two tables each with two columns? Normally here is how I would do it:

create table tab1
(account integer,
link serial)

create table tab1_link
(link integer, -- links to tab1.link
field2 char(40))
~
~

Reply With Quote
  #2  
Old   
Art Kagel
 
Posts: n/a

Default Re: Master/detail with one table - 04-16-2012 , 12:24 PM






Actually, since the key to tab1 is already an integer, there is no value
gained to introducing an artificial serial type key, so I would normally
just do:

create table tab1 (
account integer
);

create tablet tab2 (
account integer,
field2 char(40)
);

alter table tab1 add constraint primary key(account);
alter table tab2 add constraint foreign key(account) references
tab1(account);

However, as you point out, there will only be a total of 12 rows in the
result set when these two tables are joined, so there isn't much harm in
denormalizing this a bit and making it just one table. It will eliminate
the overhead of the foreign key index on tab2 (which is optional beginning
in Informix v11.70 anyway). You should still probably have an index on
account (though not a unique index) or better just a single unique index on
account and field2.

Art

Art S. Kagel
Advanced DataTools (www.advancedatatools.com)
Blog: http://informix-myview.blogspot.com/

Disclaimer: Please keep in mind that my own opinions are my own opinions
and do not reflect on my employer, Advanced DataTools, the IIUG, nor any
other organization with which I am associated either explicitly,
implicitly, or by inference. Neither do those opinions reflect those of
other individuals affiliated with any entity with which I am affiliated nor
those of the entities themselves.



On Mon, Apr 16, 2012 at 10:03 AM, loc <c320sky (AT) gmail (DOT) com> wrote:

Quote:
To keep a database normalized should a one to many relationship always use
two tables? The data in the following table is used as a master record,
once it's setup it will rarely be changed or have more rows added to it.

create table tab1
(account integer,
field2 char(40))

There will be about 4 unique values for tab1.account and about 3
associated rows for tab1.field2. Since the data set is so small would it
be better to just put it all into one table with two columns rather than
two tables each with two columns? Normally here is how I would do it:

create table tab1
(account integer,
link serial)

create table tab1_link
(link integer, -- links to tab1.link
field2 char(40))
~
~
_______________________________________________
Informix-list mailing list
Informix-list (AT) iiug (DOT) org
http://www.iiug.org/mailman/listinfo/informix-list

Reply With Quote
  #3  
Old   
loc
 
Posts: n/a

Default Re: Master/detail with one table - 04-16-2012 , 01:22 PM



On Monday, April 16, 2012 1:24:47 PM UTC-4, Art S. Kagel wrote:
Quote:
Actually, since the key to tab1 is already an integer, there is no value gained to introducing an artificial serial type key, so I would normally just do:

create table tab1 (
**** account integer
);

create tablet tab2 (


**** account integer,
**** field2 char(40)
);

alter table tab1 add constraint primary key(account);
alter table tab2 add constraint foreign key(account) references tab1(account);

However, as you point out, there will only be a total of 12 rows in the result set when these two tables are joined, so there isn't much harm indenormalizing this a bit and making it just one table.* It will eliminate the overhead of the foreign key index on tab2 (which is optional beginning in Informix v11.70 anyway).* You should still probably have an index onaccount (though not a unique index) or better just a single unique index on account and field2.



Art

Art S. Kagel
Advanced DataTools (<a href="http://www.advancedatatools.com" target="_blank">www.advancedatatools.com</a><span style="padding-right:16px;width:16px;min-height:16px"></span>)


Blog: <a href="http://informix-myview.blogspot.com/" target="_blank">http://informix-myview.<WBR>blogspot.com/</a><span style="padding-right:16px;width:16px;min-height:16px"></span



Disclaimer: Please keep in mind that my own opinions are my own opinions and do not reflect on my employer, Advanced DataTools, the IIUG, nor any other organization with which I am associated either explicitly, implicitly, or by inference.* Neither do those opinions reflect those of other individuals affiliated with any entity with which I am affiliated nor those of the entities themselves.







On Mon, Apr 16, 2012 at 10:03 AM, loc <span dir="ltr">&lt;<a href="mailto:c320sky (AT) gmail (DOT) com" target="_blank">c320sky (AT) gmail (DOT) com</a>></span> wrote:
blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"

To keep a database normalized should a one to many relationship always use two tables? *The data in the following table is used as a master record, once it's setup it will rarely be changed or have more rows added to it.





create table tab1

*(account integer,

*field2 char(40))



There will be about 4 unique values for tab1.account and about 3 associated rows for tab1.field2. *Since the data set is so small would it be better to just put it all into one table with two columns rather than two tables each with two columns? *Normally here is how I would do it:





create table tab1

*(account integer,

* link serial)



create table tab1_link

*(link integer, -- links to tab1.link

* field2 char(40))

~

~

______________________________<WBR>_______________ __

Informix-list mailing list

a href="mailto:Informix-list (AT) iiug (DOT) org" target="_blank">Informix-list (AT) iiug (DOT) org</a

a href="http://www.iiug.org/mailman/listinfo/informix-list" target="_blank">http://www.iiug.org/mailman/<WBR>listinfo/informix-list</a><span style="padding-right:16px;width:16px;min-height:16px"></span



/blockquote></div
Art,

If it were your database would you use just the one table or two? I guess my question is should I use two tables just for the sake of keeping things normalized? Would having only one table even qualify as denormalized, since there isn't any data duplication, except the primary key which would be anyway.

Reply With Quote
  #4  
Old   
Art Kagel
 
Posts: n/a

Default Re: Master/detail with one table - 04-16-2012 , 01:32 PM



I would keep i normalized in two tables. Make sure you have a unique key
on the tab2 table to prevent anyone from entering the same value twice.

Art

Art S. Kagel
Advanced DataTools (www.advancedatatools.com)
Blog: http://informix-myview.blogspot.com/

Disclaimer: Please keep in mind that my own opinions are my own opinions
and do not reflect on my employer, Advanced DataTools, the IIUG, nor any
other organization with which I am associated either explicitly,
implicitly, or by inference. Neither do those opinions reflect those of
other individuals affiliated with any entity with which I am affiliated nor
those of the entities themselves.



On Mon, Apr 16, 2012 at 2:22 PM, loc <c320sky (AT) gmail (DOT) com> wrote:

Quote:
On Monday, April 16, 2012 1:24:47 PM UTC-4, Art S. Kagel wrote:
Actually, since the key to tab1 is already an integer, there is no value
gained to introducing an artificial serial type key, so I would normally
just do:

create table tab1 (
account integer
);

create tablet tab2 (


account integer,
field2 char(40)
);

alter table tab1 add constraint primary key(account);
alter table tab2 add constraint foreign key(account) references
tab1(account);

However, as you point out, there will only be a total of 12 rows in the
result set when these two tables are joined, so there isn't much harm
in denormalizing this a bit and making it just one table. It will
eliminate the overhead of the foreign key index on tab2 (which is optional
beginning in Informix v11.70 anyway). You should still probably have an
index on account (though not a unique index) or better just a single unique
index on account and field2.



Art

Art S. Kagel
Advanced DataTools (<a href="http://www.advancedatatools.com"
target="_blank">www.advancedatatools.com</a><span
style="padding-right:16px;width:16px;min-height:16px"></span>)


Blog: <a href="http://informix-myview.blogspot.com/" target="_blank"
http://informix-myview.<WBR>blogspot.com/</a><span
style="padding-right:16px;width:16px;min-height:16px"></span



Disclaimer: Please keep in mind that my own opinions are my own opinions
and do not reflect on my employer, Advanced DataTools, the IIUG, nor any
other organization with which I am associated either explicitly,
implicitly, or by inference. Neither do those opinions reflect those of
other individuals affiliated with any entity with which I am affiliated nor
those of the entities themselves.







On Mon, Apr 16, 2012 at 10:03 AM, loc <span dir="ltr">&lt;<a
href="mailto:c320sky (AT) gmail (DOT) com" target="_blank">c320sky (AT) gmail (DOT) com</a>></span
wrote:
blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px
#ccc solid;padding-left:1ex"

To keep a database normalized should a one to many relationship always
use two tables? The data in the following table is used as a master
record, once it's setup it will rarely be changed or have more rows
added to it.





create table tab1

(account integer,

field2 char(40))



There will be about 4 unique values for tab1.account and about 3
associated rows for tab1.field2. Since the data set is so small would it
be better to just put it all into one table with two columns rather than
two tables each with two columns? Normally here is how I would do it:





create table tab1

(account integer,

link serial)



create table tab1_link

(link integer, -- links to tab1.link

field2 char(40))

~

~

______________________________<WBR>_______________ __

Informix-list mailing list

a href="mailto:Informix-list (AT) iiug (DOT) org" target="_blank"
Informix-list (AT) iiug (DOT) org</a

a href="http://www.iiug.org/mailman/listinfo/informix-list"
target="_blank">http://www.iiug.org/mailman/<WBR>listinfo/informix-list</a><span
style="padding-right:16px;width:16px;min-height:16px"></span



/blockquote></div

Art,

If it were your database would you use just the one table or two? I guess
my question is should I use two tables just for the sake of keeping things
normalized? Would having only one table even qualify as denormalized,
since there isn't any data duplication, except the primary key which would
be anyway.
_______________________________________________
Informix-list mailing list
Informix-list (AT) iiug (DOT) org
http://www.iiug.org/mailman/listinfo/informix-list

Reply With Quote
Reply




Thread Tools
Display Modes

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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.