CodeCharge Studio
search Register Login  

Visual PHP Web Development

Visually Create Internationalized Web Applications, Web Reports, Calendars, and more.
CodeCharge.com

YesSoftware Forums -> Archive -> CodeChargeStudio.Discussion

 DB QUESTION: Dupe or unique field names???

Print topic Send  topic

Author Message
Chip Cotton
Posted: 08/19/2002, 7:36 AM

The 'school' of database programming I came from taught me that NO TWO
FIELDS in a database should have the same name. This avoids confusion
as to which table a given field is in.

Of course, one can use the table.fieldname syntax to avoid this
confusion, but the fieldname alone is used in many parts of an
application.

This being the case, I have been in the habit of uniquely naming
fields, usually giving the table a 1 or 2 letter prefix followed by
the field name.

BUT I FOUND SOMETHING INTERESTING ABOUT CODECHARGE

By *accident*, I left a foreign key field in a 'many' table the same
field name as the 'one to' table.

f_id <-> f_id

When I dragged the tables into the CCS query builder for a form, CCS
automatically linked the fields!

OK, I have to ask, SHOULD I BE naming some fields with the same name?
Charly Crembil
Posted: 08/19/2002, 7:40 AM

Hehe, the CCS Tutorial shows the same scenario. And after read it, I've made
myself the same question...
Regards,
Carlos.

"Chip Cotton" <please.no.email@Jail-Spammers.com> escribió en el mensaje
news:r802mu8dqn2cehrpgmvhh4bevfv345kqd6@4ax.com...
> The 'school' of database programming I came from taught me that NO TWO
> FIELDS in a database should have the same name. This avoids confusion
> as to which table a given field is in.
>
> Of course, one can use the table.fieldname syntax to avoid this
> confusion, but the fieldname alone is used in many parts of an
> application.
>
> This being the case, I have been in the habit of uniquely naming
> fields, usually giving the table a 1 or 2 letter prefix followed by
> the field name.
>
> BUT I FOUND SOMETHING INTERESTING ABOUT CODECHARGE
>
> By *accident*, I left a foreign key field in a 'many' table the same
> field name as the 'one to' table.
>
> f_id <-> f_id
>
> When I dragged the tables into the CCS query builder for a form, CCS
> automatically linked the fields!
>
> OK, I have to ask, SHOULD I BE naming some fields with the same name?

AaronJ
Posted: 08/20/2002, 9:54 AM

The school I came from says that if the key is the same value in both
tables, then a relationship is implied.
And yes they should be named the same if they are the same key/value.. in my
book. What's the logic in trying to name foreign keys different in each
table when they are all used for the same purpose? Also, this is a little
bit database specific, since if I were able to identify the key as a foreign
key with a contstraint I might be more willing to name it anything (I am in
mysql).

Just my thoughts...



"Charly Crembil" <nouser@hotmail.com> wrote in message
news:ajr017$b18$1@news.codecharge.com...
> Hehe, the CCS Tutorial shows the same scenario. And after read it, I've
made
> myself the same question...
> Regards,
> Carlos.
>
> "Chip Cotton" <please.no.email@Jail-Spammers.com> escribió en el mensaje
>news:r802mu8dqn2cehrpgmvhh4bevfv345kqd6@4ax.com...
> > The 'school' of database programming I came from taught me that NO TWO
> > FIELDS in a database should have the same name. This avoids confusion
> > as to which table a given field is in.
> >
> > Of course, one can use the table.fieldname syntax to avoid this
> > confusion, but the fieldname alone is used in many parts of an
> > application.
> >
> > This being the case, I have been in the habit of uniquely naming
> > fields, usually giving the table a 1 or 2 letter prefix followed by
> > the field name.
> >
> > BUT I FOUND SOMETHING INTERESTING ABOUT CODECHARGE
> >
> > By *accident*, I left a foreign key field in a 'many' table the same
> > field name as the 'one to' table.
> >
> > f_id <-> f_id
> >
> > When I dragged the tables into the CCS query builder for a form, CCS
> > automatically linked the fields!
> >
> > OK, I have to ask, SHOULD I BE naming some fields with the same name?
>
>

RonB
Posted: 08/22/2002, 2:48 AM

Hate to disagree. Giving fields in different tables the same name is not a
whise thing to do. OK it's nice to see CCS linking automaticaly when the
names are the same but that's just a minor pro. The con's are far greater.
If you ever have to write more complex sql statements yourself you will
probably curse yourself for using the same fieldnames in different tables as
this forces you to write full table.fieldnames in every table you want to
use where names are the same. The query builder is great for simple queries
but when complex joins are a must you will have to write the sql yourself. I
don't know wich school advises you to name them the same but it's not a wise
suggestion. I myself use 2 or three letters from the table name and then the
field name so table articles could look like this:
art_id
art_title
art_date
art_emp_id

in wich art_emp_id is the emp_id in the employee table

Believe me in the end, if you ever have to write sql yourself, you will be
glad you didn't use the same fieldnames. Just think about about a query over
3 or 4 tables having to write all fieldnames in table.fieldname format. It
becomes a lot of work very fast.

RonB


"AaronJ" <aaronjudd@coolersites.com> schreef in bericht
news:ajts81$fku$1@news.codecharge.com...
> The school I came from says that if the key is the same value in both
> tables, then a relationship is implied.
> And yes they should be named the same if they are the same key/value.. in
my
> book. What's the logic in trying to name foreign keys different in each
> table when they are all used for the same purpose? Also, this is a little
> bit database specific, since if I were able to identify the key as a
foreign
> key with a contstraint I might be more willing to name it anything (I am
in
> mysql).
>
> Just my thoughts...
>
>
>
> "Charly Crembil" <nouser@hotmail.com> wrote in message
>news:ajr017$b18$1@news.codecharge.com...
> > Hehe, the CCS Tutorial shows the same scenario. And after read it, I've
> made
> > myself the same question...
> > Regards,
> > Carlos.
> >
> > "Chip Cotton" <please.no.email@Jail-Spammers.com> escribió en el mensaje
> >news:r802mu8dqn2cehrpgmvhh4bevfv345kqd6@4ax.com...
> > > The 'school' of database programming I came from taught me that NO TWO
> > > FIELDS in a database should have the same name. This avoids confusion
> > > as to which table a given field is in.
> > >
> > > Of course, one can use the table.fieldname syntax to avoid this
> > > confusion, but the fieldname alone is used in many parts of an
> > > application.
> > >
> > > This being the case, I have been in the habit of uniquely naming
> > > fields, usually giving the table a 1 or 2 letter prefix followed by
> > > the field name.
> > >
> > > BUT I FOUND SOMETHING INTERESTING ABOUT CODECHARGE
> > >
> > > By *accident*, I left a foreign key field in a 'many' table the same
> > > field name as the 'one to' table.
> > >
> > > f_id <-> f_id
> > >
> > > When I dragged the tables into the CCS query builder for a form, CCS
> > > automatically linked the fields!
> > >
> > > OK, I have to ask, SHOULD I BE naming some fields with the same name?
> >
> >
>
>

Carl
Posted: 08/28/2002, 7:06 PM


"Chip Cotton" <please.no.email@Jail-Spammers.com> wrote in message
news:r802mu8dqn2cehrpgmvhh4bevfv345kqd6@4ax.com...
> The 'school' of database programming I came from taught me that NO TWO
> FIELDS in a database should have the same name. This avoids confusion
> as to which table a given field is in.
>
> Of course, one can use the table.fieldname syntax to avoid this
> confusion, but the fieldname alone is used in many parts of an
> application.
>
> This being the case, I have been in the habit of uniquely naming
> fields, usually giving the table a 1 or 2 letter prefix followed by
> the field name.
>
> BUT I FOUND SOMETHING INTERESTING ABOUT CODECHARGE
>
> By *accident*, I left a foreign key field in a 'many' table the same
> field name as the 'one to' table.
>
> f_id <-> f_id
>
> When I dragged the tables into the CCS query builder for a form, CCS
> automatically linked the fields!
>
> OK, I have to ask, SHOULD I BE naming some fields with the same name?

Carl
Posted: 08/28/2002, 7:10 PM

Ditto. I always use to prefix field names with one or two letters implying
the table. This was for my own sanity. So if there's a field called "num"
in the customer table order header table I would call it cnum and hnum
respectively. So I always new it was "num" but with the appropriate prefix.
If your db only has 2 or three tables with few fields it may be irrelevant,
but when you get into more and larger tables it makes life simpler.

If you look at humongous databases (thousands of tables) such as JD Edwards
uses, they follow this type of naming convention also.

Carl

"Chip Cotton" <please.no.email@Jail-Spammers.com> wrote in message
news:r802mu8dqn2cehrpgmvhh4bevfv345kqd6@4ax.com...
> The 'school' of database programming I came from taught me that NO TWO
> FIELDS in a database should have the same name. This avoids confusion
> as to which table a given field is in.
>
> Of course, one can use the table.fieldname syntax to avoid this
> confusion, but the fieldname alone is used in many parts of an
> application.
>
> This being the case, I have been in the habit of uniquely naming
> fields, usually giving the table a 1 or 2 letter prefix followed by
> the field name.
>
> BUT I FOUND SOMETHING INTERESTING ABOUT CODECHARGE
>
> By *accident*, I left a foreign key field in a 'many' table the same
> field name as the 'one to' table.
>
> f_id <-> f_id
>
> When I dragged the tables into the CCS query builder for a form, CCS
> automatically linked the fields!
>
> OK, I have to ask, SHOULD I BE naming some fields with the same name?


   


These are Community Forums for users to exchange information.
If you would like to obtain technical product help please visit http://support.yessoftware.com.

MS Access to Web

Convert MS Access to Web.
Join thousands of Web developers who build Web applications with minimal coding.

CodeCharge.com

Home   |    Search   |    Members   |    Register   |    Login


Powered by UltraApps Forum created with CodeCharge Studio
Copyright © 2003-2004 by UltraApps.com  and YesSoftware, Inc.