Quote:
I’ve got a table, with an item
_type field [sic: columns are not fields]
|
Please be polite enough to post DDL, as required by Netiquette. You
also missed a basic term and do not follow ISO-11179 naming rules for
data elements.
Quote:
The value of this field [sic] is 1-6, and I’ve created 6 views based on this
field [sic], returning the same data set but from different fields
|
[sic] in the
table. Then I create a VIEW which is the UNION of these 6 views, see
below <<
UNIONs are pretty rare in a properly designed schema. Where is that
DDL?
Quote:
When I execute this in the SQL 2005 EM without the ‘item_nbr_description’ field [sic, and that needs to be a “<something>_item_nbr_description”], the 9 rows return in < 1 sec. If I include the item_nbr_description field [sic] (max len is 62 chars), it takes 4 secs to return the same 9 rows |
Almost all of your data element names are useless and vague.
Item_what? vague_seq? Like a physical ordering? It also looks like you
actually modeled a physical line number from the paper forms in your
database! Why do you have all those silly Qry_Parts_Quote_Details_#
tables? SQL programmers and RDBMS hate repeated groups, split tables
and other forms of redundancy.
Also the idiom for a UNION is to name the columns in the alias:
SELECT X.*
FROM (SELECT parts_quote_id, line_nbr, vague_seq, item_nbr_type,
item_nbr, item_nbr_description
FROM Qry_Parts_Quote_Details_1
UNION
SELECT parts_quote_id, line_nbr, vague_seq, item_nbr_type,
item_nbr, item_nbr_description
FROM Qry_Parts_Quote_Details_2
..)
AS X(parts_quote_id, line_nbr, vague_seq, item_nbr_type,
item_nbr, item_nbr_description)
WHERE parts_quote_id = 2546;
Please try again.