List:General Discussion« Previous MessageNext Message »
From:Rick James Date:May 21 2012 6:57pm
Subject:RE: create alias for columns bound to database?
View as plain text  
Instead of
SELECT tla_foo
FROM ThreeLetterAcronym
JOIN ...

I prefer
SELECT tla.foo   -- Note "." instead of "_"
FROM ThreeLetterAcronym AS tla
JOIN ...

Using aliases is mandatory when a "self join" is used.

> -----Original Message-----
> From: Johan De Meersman [mailto:vegivamp@stripped]
> Sent: Monday, May 21, 2012 5:27 AM
> To: Rick James
> Cc: dante@stripped; mysql@lists.mysql.com
> Subject: Re: create alias for columns bound to database?
> 
> ----- Original Message -----
> > From: "Rick James" <rjames@stripped>
> >
> > * should not begin with the table name
> 
> Personally, I tend to prefix all column names with three-letter
> abbreviations of the table name, so that they are both unique across
> joins, and it's obvious what table they're from wherever they appear.
> 
> > * ids should be spelled the same between tables (`foo_id` both where
> > it is the PK, and where it is a FK)
> 
> Yeps, and together with the above convention it is also immediately
> clear what table that key links to.
> 
> Beyond that, make names descriptive. Don't use field_1, field_2 and
> field_3; call them name, age and gender.
> 
> --
> Bier met grenadyn
> Is als mosterd by den wyn
> Sy die't drinkt, is eene kwezel
> Hy die't drinkt, is ras een ezel
Thread
create alias for columns bound to database?D. Dante Lorenso18 May
  • RE: create alias for columns bound to database?David Lerer18 May
  • RE: create alias for columns bound to database?Rick James18 May
    • Re: create alias for columns bound to database?Johan De Meersman21 May
      • RE: create alias for columns bound to database?Rick James21 May