In general I list the fields because it is clearer to
have the list in front of me, but sometimes, especially during development
when the list of fields may change, SELECT * offers convenience.
Remember, the rule of thumb is, never used SELECT * in _production_
code; I'm sure we all use SELECT * at some point during development.
As reagards maintenance, adding columns to the table is not so bad but
problems tend to arise when a column removed from the table or an
existing column's name or ordinal position in the schema catalog
changes (e.g. SELECT * used to spit out columns last_name then
first_name and now SELECT * expands to first_name then last_name).
Issues range from having to change code that consumes the query
regardless (i.e. you haven't saved much on maintenance) to queries
failing. As regards SQL statements ('query' is often used in the
context of access to mean a SQL statement e.g. 'DELETE query'), data
can end up being written to wrong columns and isn't spotted for some
time e.g.
INSERT INTO A
SELECT * FROM B;
Introducing risk to save some typing isn't my style.
It's worth noting the execptional cases e.g. COUNT(*) which is
overloaded to count rows rather than values, NOT EXIST (SELECT *
FROM...) which doesn't return a set but a TRUE/FALSE/UNKNOWN result.
Aside: I've been noticing DELETE * around here a lot. A while ago I
was trying to explain to a colleague, who was wondering why he was
getting a syntax error in SQL Server, that DELETE * makes no sense
because DELETE operates on rows and not columns. "What would you
expect DELETE <column_name> FROM <table_name> to do?" I enquired.
"Delete just that column," came the reply. "What do you mean, DROP the
column from the table?" I pursued. "No, just set the values to null."
I was just about enquire about NOT NULL columns when I came to my
senses and convinced him to disengage brain and simply remember the
rule of thumb, never use DELETE *.
Jamie.
--