Re: Create indexed view

From: Tom Moreau (tom_at_dont.spam.me.cips.ca)
Date: 03/19/04


Date: Fri, 19 Mar 2004 06:08:32 -0500

See my answer to the same question elsewhere in this group - and please
don't multi-post.

-- 
   Tom
----------------------------------------------------
Thomas A. Moreau, BSc, PhD, MCSE, MCDBA
SQL Server MVP
Columnist, SQL Server Professional
Toronto, ON   Canada
www.pinnaclepublishing.com/sql
.
"Dejan Markic" <dejan@akton.is> wrote in message
news:XXy6c.6573$%x4.871293@news.siol.net...
Hello!
I've read all that ... I'm just interested about the query with which I can
create an indexed view ... A query that would do the same as UNION ALL, but
would allow me to create an indexed view.
Right now I have a quiry that looks like this:
select id,name from t1 union all
select id,name from t2
Now, I cannot create indexed view because this query uses UNION ... is there
another way to get records from many tables?
Kind regards,
Dejan
[Change TLD from .is to .si]
"Adam Machanic" <amachanic@air-worldwide.nospamallowed.com> wrote in message
news:O8pHbePDEHA.2600@TK2MSFTNGP09.phx.gbl...
| Look up the BOL article titled "Creating an Indexed View".  There are a
lot
| of things you need to do in order to qualify for indexed view creation,
| including schema binding, not using SELECT *, including a COUNT_BIG() in
| your SELECT list, etc... They're all listed there.  Keep in mind that
| indexed views were created for automatic enhancement of aggregate queries
| that had already been written against base tables (the query optimizer
knows
| to look for indexed views if they're available and use them instead of the
| base tables for aggregate queries... That's what the COUNT_BIG() is for).
| You'll also have other issues in order to make the query optimizer
properly
| use your view because it's partitioned.  Another BOL article you should
| check out is "Using Partitioned Views".
|
|
| "Dejan Markic" <dejan@akton.is> wrote in message
| news:2Tg6c.6536$%x4.865008@news.siol.net...
| > Hello!
| >
| > I have three or more tables, each table holds data for one month. Now I
| want
| > to create a view where I would be able to select data from different
| months.
| > I tried to make a view like this:
| > select * from t1 UNION ALL
| > select * from t2 UNION ALL
| > select * from t3 ...
| >
| > ...
| > And it would work OK, but according to documentation this is not an
| indexed
| > view and I cannot create indexes on it. Can I create that view in some
| other
| > way to get the same data and that this view would qualify as index view?
| >
| > Or other way ... if I use indexes on participating tables ... would that
| > help? I hear view would hurt the performace if it is not indexed view?
| >
| > Thanks for you input!
| >
| > Kind regards,
| > Dejan
| >
| >
|
|


Relevant Pages

  • Re: question about a query
    ... JOIN QuesNans AS B ON A.topicid = B.topicid ... CROSS JOIN (SELECT 1 AS n UNION ALL ... This is a crosstab query. ... Erland Sommarskog, SQL Server MVP, esquel@xxxxxxxxxxxxx ...
    (comp.databases.ms-sqlserver)
  • Re: Error using a derived table
    ... to re-write your query without all of the nested SELECTs and the CASE ... > union all ... > select s.misspelledname as 'Resortname' ... I am using SQL Server 2000 EE. ...
    (microsoft.public.sqlserver.programming)
  • Re: Indexes being improperly used when selecting data through a view
    ... I run the same query against the table directly and it looks ... What happens if you actually have the UNION ALL, ... With UNION SQL Server will have to do an operation ... Books Online for SQL Server 2005 at ...
    (comp.databases.ms-sqlserver)
  • Re: Establishing Precedence In ORDERBY Condition Causing Problems.
    ... in the query, prefix all your columns with aliases (or the table ... of the procedure to avoid duplicates it seems to have thrown off the ... Erland Sommarskog, SQL Server MVP, esquel@xxxxxxxxxxxxx ...
    (comp.databases.ms-sqlserver)
  • Re: question about a query
    ... JOIN QuesNans AS B ON A.topicid = B.topicid ... CROSS JOIN (SELECT 1 AS n UNION ALL ... This is a crosstab query. ... Books Online for SQL Server 2005 athttp://www.microsoft.com/technet/prodtechnol/sql/2005/downloads/books ... ...
    (comp.databases.ms-sqlserver)