Home » SQL & PL/SQL » SQL & PL/SQL » best practices writing a query
best practices writing a query [message #436698] Fri, 25 December 2009 15:09 Go to next message
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 Go to previous messageGo to next message
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 Go to previous message
Kevin Meade
Messages: 2098
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
Previous Topic: restore the view after update/replace the view
Next Topic: Need help with Procedure Error Handling
Goto Forum:
  


Current Time: Sun Sep 25 11:10:19 CDT 2016

Total time taken to generate the page: 0.06893 seconds