Roy, I understand the point you are trying to make, but this part of
your argument just doesn't hold up to scrutiny:
> But if you see * in one of my SELECT lists in production code it does
> not mean I was lazy. It means that the REQUIREMENT is to return EVERY
> row in the table.
If it's a requirement, why don't you type the columns out? Even if a
column is added, it's no easier (or more difficult) to recompile the
view than it is to add the column as required.
I understand the point that you're trying to make, and I think you're
right about the potential value of SELECT * when used correctly, but
I'm hard pressed to find a scenario where SELECT * is preferable to
typing column names out.
Stu
Roy Harvey wrote:
> On Mon, 03 Jul 2006 13:41:44 -0700, darter <dd@.email.com> wrote:
>
> Personally I am quite tired of this conventional wisdom.
> Of course, if you do not need every column returned you should specify
> just the columns you need. I have no problem with that.
>
> Simple example: a view that starts with an existing table and adds
> some columns by joining or a subquery. This calls for a qualified *:
> CREATE VIEW Something_V
> AS
> SELECT A.*,
> (<subquery> ) as X,
> (<subquery> ) as Y
> FROM Something as A
> If a new column is added to A there is no question that it belongs in
> the view, and no question that a recompile will add it.
> With * the sequence of the columns is predictable. There is no chance
> that a column will be left out. There is no chance that a comma will
> be left out, skipping a column and assigning its name to a different
> column.
> Yes, * is often abused, but it is also a valuable feature when used
> correctly.
> Roy Harvey
> Beacon Falls, CT> How about comparing a table against an Oracle or DB2 table? Naturally
> you would want to grab all the columns, as any disrepancy in column
> names or their count would mean tables are not idential.
This sounds like an administrative task, not something that should naturally
appear in your application.
Anyway, I would rely on the metadata tables / catalog views to describe my
tables, not SELECT *.|||On 3 Jul 2006 19:42:49 -0700, "Stu" <stuart.ainsworth@.gmail.com>
wrote:
>Roy, I understand the point you are trying to make, but this part of
>your argument just doesn't hold up to scrutiny:
>
>If it's a requirement, why don't you type the columns out?
Because it is no longer obvious that it is a requirement.
>Even if a
>column is added, it's no easier (or more difficult) to recompile the
>view than it is to add the column as required.
Adding the column name is certainly not hard, but pulling up the ALTER
script and hitting execute is certainly easier, and provides less
opportunities for errors.
>I understand the point that you're trying to make, and I think you're
>right about the potential value of SELECT * when used correctly, but
>I'm hard pressed to find a scenario where SELECT * is preferable to
>typing column names out.
OK, suppose I have a table with 30 columns. Rather than use *, I have
included all 30 column names. Six months later, someone else is
spending their day going through the code making sure they understand
what it does. They see all those column names, and they wonder, is
that all of them? Or only most of them? And they have to start
counting, ormatching them up. And now imagine that the order was
changed. I simply do not see what has been accomplished by replacing
the clarity of * with the relative obscurity of a list column names.
>Stu
Roy
No comments:
Post a Comment