My favorite SQL tutorial: http://sqlzoo.net/

Do your field names need to be globally unique: yes and no.  Some design 
philosophies require that every field on every table be uniquely 
identified. The only uniqueness requirement you must obey is that no two 
fields on the same table can have the same name. What you call your fields 
should reflect the data that's in them and not be too much of a hassle to 
type (not strangely punctuated)

For me, I personally do not use tablename_fieldname to name my fields. 
This disagrees with several style doctrines but it works for me. 

When you join two tables that share field names, both fields will appear 
in the result (named identically)., Your naming pattern would avoid that 
except in the case of self-joins (one table that joins to itself). The 
other way to avoid duplicate field names in your output is to use the 
"alias" feature of SQL.

Let's say you have a table of employees. Each employee gets an ID value, 
has a name, a department, and a boss (identified by it's id value). One 
way to buld this table would look like

CREATE TABLE employee {
        id int auto_increment
        , boss_employee_id int
        , department varchar(16)
        , lastname varchar(32)
        , firstname varchar(32)
        , PRIMARY KEY(id)
        , UNIQUE(firstname, lastname)
}
(using my preferred naming pattern)

I used "boss_employee_id" instead of "boss_id" because I wanted to 
indicate both what the field contained and where the data came from. Most 
of my fields with _ in their names point to data in other tables, some 
just looked better with the spacer.

If you have tried the tutorial and are still lost, let us know and someone 
will happily work with you.

Shawn Green
Database Administrator
Unimin Corporation - Spruce Pine



Rich <[EMAIL PROTECTED]> wrote on 10/04/2005 12:43:17 PM:

> Hi folks.  Any chance on a tutorial from joins?  I find them totally
> confusing and I know there's some power in them, so I need to learn 
them.
> 
> Having asked that, another question arises...do my field names in 
different
> tables within the same database have to overlap (same field name) in 
order
> for joins to work?  I'm currently naming fields in such a manner:
> 
> TABLE1
> table1_alpha
> table1_bravo
> 
> TABLE2
> table2_firstname
> table2_lastname
> 
> Appreciate any guidance on these two questions.
> 
> Cheers
> 
> 
> 
> -- 
> MySQL General Mailing List
> For list archives: http://lists.mysql.com/mysql
> To unsubscribe:    http://lists.mysql.com/[EMAIL PROTECTED]
> 

Reply via email to