best practices writing a query [message #436698] |
Fri, 25 December 2009 15:09 |
miroconnect@yahoo.com
Messages: 202 Registered: April 2006
|
Senior Member |
|
|
here ia simple query written with differn alias
select
ag.sys_audit_id ,ap.SYS_AUDIT_PROG_ID
from
ea_audit_general ag , ea_audit_program ap
where ag.SYS_AUDIT_ID=ap.SYS_AUDIT_ID
select
a.sys_audit_id ,b.SYS_AUDIT_PROG_ID
from
ea_audit_general a , ea_audit_program b
where a.SYS_AUDIT_ID=b.SYS_AUDIT_ID
I always go with the first approach where the alias of the table is sought of abbreviation of table name and second sql just uses vague alphabets as table alias , which one is considered as best practice , if the first one is please give me some reasons so that I tell it to other team members
|
|
|
Re: best practices writing a query [message #436699 is a reply to message #436698] |
Fri, 25 December 2009 15:19 |
Its_me_ved
Messages: 979 Registered: October 2009 Location: India
|
Senior Member |
|
|
A good naming conventions make it easier to debug and make your code more readable.
instead of
select
a.sys_audit_id ,b.SYS_AUDIT_PROG_ID
from
ea_audit_general a , ea_audit_program b
where a.SYS_AUDIT_ID=b.SYS_AUDIT_ID
I would prefer to go with like below if there are more table join and the query is a complex one
select
eag.sys_audit_id ,eap.SYS_AUDIT_PROG_ID
from
ea_audit_general eag , ea_audit_program eap
where eag.SYS_AUDIT_ID=eap.SYS_AUDIT_ID
[Updated on: Fri, 25 December 2009 15:20] Report message to a moderator
|
|
|
Re: best practices writing a query [message #436826 is a reply to message #436698] |
Mon, 28 December 2009 12:53 |
|
Kevin Meade
Messages: 2103 Registered: December 1999 Location: Connecticut USA
|
Senior Member |
|
|
It always amazes me how lazy people get in this business. Now most of the time I think being lazy in the business is a good thing because it drives most of us to actually work smarter rather than harder. It is part of the nature of a coach potatoe to build a better remote.
So I have to wonder why my favorite variation of aliases is so often skipped. I mean if the reason for using aliases is clarity then how much clearer can you get than this?
select
ea_audit_general.sys_audit_id
, ea_audit_program.SYS_AUDIT_PROG_ID
from
ea_audit_general
, ea_audit_program
where ea_audit_general.SYS_AUDIT_ID = ea_audit_program.SYS_AUDIT_ID
/
Kevin
|
|
|