Re: Efficient query to fetch the columns in an entire relation?

From: Ruud de Koter <ruud_dekoter_at_hp.com>
Date: Fri, 19 Jul 2002 10:20:50 +0200
Message-ID: <3D37CBE2.F0418762_at_hp.com>


Tobin Harris wrote:
>
> > Yesterday, I came across one simple question yet interesting.
> >
> > What is the best way of retrieving all columns in a given relation
> > using a SQL query.
> >
> > Two possible alternatives are
> >
> > 1. SELECT * FROM relation_name;
> >
> > 2. SELECT COLUMN1, COLUMN2, ..., COLUMNn FROM relation_name;
> >
> > I am not able to decide, which is better than the other and more
> > importantly
> > WHY?
>
> I'm pretty sure that option 2 is best. If you explicitly state the columns
> you want, the database doesn't have to waste effort querying the
> data-dictionary to work out what columns are available to select.
>
As usual, the crux is in the operationalization of 'best'. An alternative approach: if you want something that will always return all columns, even in an environment where tables are changed regularly, you should use the 'select *'. It is amore robust and low maintenance solution.

Regards,

Ruud.

> Tobin
>
> > Hope to get some reply on this,
> >
> > - Vijay

-- 
--------------------------------------------------------------------------------------
Ruud de Koter                    HP OpenView Software Business Unit
Senior Software Engineer         IT Service Management Operation
Telephone: +31 (20) 514 15 89    Van Diemenstraat 200  
Telefax  : +31 (20) 514 15 90    PO Box 831
Telnet   : 547 - 1589            1000 AV  Amsterdam, the Netherlands
Email    : ruud_dekoter_at_hp.com

internet: http://www.openview.hp.com/products/servicedesk
intranet: http://ovweb.bbn.hp.com/itservicemanager
--------------------------------------------------------------------------------------
Received on Fri Jul 19 2002 - 10:20:50 CEST

Original text of this message