Sunday, February 19, 2012

Indexed Views over a Partitioning scheme table

Hello all, I was wondering if anyone as found any information on weather or
not you can place a index view over a partitioning scheme in SQL server 2005.
I have successfully setup a 89 partitioned scheme in SQL 2005 (that works
well) though I also need to build a materialized view over that newly
partitioned data. Oddly I continue to receive an error when I attempt to
place the clustered index on the view.
ERROR:
TITLE: Microsoft SQL Server Management Studio
--
Create failed for Index 'cidx_client_monthcode'. (Microsoft.SqlServer.Smo)
For help, click:
http://go.microsoft.com/fwlink?ProdName=Microsoft+SQL+Server&ProdVer=9.00.2047.00&EvtSrc=Microsoft.SqlServer.Management.Smo.ExceptionTemplates.FailedOperationExceptionText&EvtID=Create+Index&LinkId=20476
--
ADDITIONAL INFORMATION:
An exception occurred while executing a Transact-SQL statement or batch.
(Microsoft.SqlServer.ConnectionInfo)
--
Cannot create the clustered index 'cidx_client_monthcode' on view
'Partition_DB.dbo.mv_SummarybyClientAndMonth' because the select list of the
view contains an expression on result of aggregate function or grouping
column. Consider removing expression on result of aggregate function or
grouping column from select list. (Microsoft SQL Server, Error: 8668)
For help, click:
http://go.microsoft.com/fwlink?ProdName=Microsoft+SQL+Server&ProdVer=09.00.2047&EvtSrc=MSSQLServer&EvtID=8668&LinkId=20476
Any thoughts
Thanks
Eric"Eric" <Eric@.discussions.microsoft.com> wrote in message
news:C5A6A5B8-FE3A-400F-A6B2-CBA75C8BBCF2@.microsoft.com...
> Hello all, I was wondering if anyone as found any information on weather
> or
> not you can place a index view over a partitioning scheme in SQL server
> 2005.
>
Yes.
drop view iv_T
drop table t
drop partition scheme ps1
drop partition function pf1
go
CREATE PARTITION FUNCTION pf1 (int)
AS RANGE LEFT FOR VALUES (1, 100, 1000);
GO
CREATE PARTITION SCHEME ps1
AS PARTITION pf1
ALL TO ( [primary] );
create table t(id int primary key, description varchar(50) null)
on ps1(id)
go
insert into t(id,description)
values (1,'a')
insert into t(id,description)
values (2,null)
go
create view iv_T
with schemabinding
as
select id, description
from dbo.t where description is not null
go
create unique clustered index ix_iv_t
on iv_T(id)
on [primary]
go
select * from t
David|||Hi David, thanks for the quick reply.
Oddly your syntax isn't much different then what I hadâ?¦ Though I did notice
that you had used a single file group. (Though that shouldn't make a
difference right?)
Thanks
Eric
"David Browne" wrote:
> "Eric" <Eric@.discussions.microsoft.com> wrote in message
> news:C5A6A5B8-FE3A-400F-A6B2-CBA75C8BBCF2@.microsoft.com...
> > Hello all, I was wondering if anyone as found any information on weather
> > or
> > not you can place a index view over a partitioning scheme in SQL server
> > 2005.
> >
> Yes.
>
> drop view iv_T
> drop table t
> drop partition scheme ps1
> drop partition function pf1
> go
> CREATE PARTITION FUNCTION pf1 (int)
> AS RANGE LEFT FOR VALUES (1, 100, 1000);
> GO
> CREATE PARTITION SCHEME ps1
> AS PARTITION pf1
> ALL TO ( [primary] );
> create table t(id int primary key, description varchar(50) null)
> on ps1(id)
>
> go
>
> insert into t(id,description)
> values (1,'a')
>
> insert into t(id,description)
> values (2,null)
> go
> create view iv_T
> with schemabinding
> as
> select id, description
> from dbo.t where description is not null
> go
> create unique clustered index ix_iv_t
> on iv_T(id)
> on [primary]
> go
> select * from t
>
> David
>
>|||Sorry in addition, I have a calculation in my view that needs to be there
seeing that the view is being generated at a higher level then the partition
tables grain level.
Here is the code to reproduce the error:
--start code
drop view iv_T
drop table t
drop PARTITION SCHEME ps1
drop PARTITION FUNCTION pf1
go
CREATE PARTITION FUNCTION pf1 (int)
AS RANGE LEFT FOR VALUES (1, 100, 1000,10000,100000,1000000,10000000);
go
CREATE PARTITION SCHEME ps1
AS PARTITION pf1
ALL TO ([primary])
go
create table t(id int primary key, description varchar(50) null, amt int null)
on ps1(id)
insert into t(id,description,amt)
values (1,'a', 100)
insert into t(id,description,amt)
values (200,'a', 100)
insert into t(id,description,amt)
values (3000,'b', 100)
insert into t(id,description,amt)
values (40000,'b', 100)
insert into t(id,description,amt)
values (500000,'c', 100)
go
create view iv_T
with schemabinding
as
select description, isnull(sum(amt),0) as amt, count_big(*) as rc
from dbo.t where description is not null
group by description
go
create unique clustered index ix_iv_t
on iv_T(description)
on [primary]
go
--end code
thanks
eric
"David Browne" wrote:
> "Eric" <Eric@.discussions.microsoft.com> wrote in message
> news:C5A6A5B8-FE3A-400F-A6B2-CBA75C8BBCF2@.microsoft.com...
> > Hello all, I was wondering if anyone as found any information on weather
> > or
> > not you can place a index view over a partitioning scheme in SQL server
> > 2005.
> >
> Yes.
>
> drop view iv_T
> drop table t
> drop partition scheme ps1
> drop partition function pf1
> go
> CREATE PARTITION FUNCTION pf1 (int)
> AS RANGE LEFT FOR VALUES (1, 100, 1000);
> GO
> CREATE PARTITION SCHEME ps1
> AS PARTITION pf1
> ALL TO ( [primary] );
> create table t(id int primary key, description varchar(50) null)
> on ps1(id)
>
> go
>
> insert into t(id,description)
> values (1,'a')
>
> insert into t(id,description)
> values (2,null)
> go
> create view iv_T
> with schemabinding
> as
> select id, description
> from dbo.t where description is not null
> go
> create unique clustered index ix_iv_t
> on iv_T(id)
> on [primary]
> go
> select * from t
>
> David
>
>|||"Eric" <Eric@.discussions.microsoft.com> wrote in message
news:42E4A88F-66C6-4D3F-8BE5-254ECF59003C@.microsoft.com...
> Sorry in addition, I have a calculation in my view that needs to be there
> seeing that the view is being generated at a higher level then the
> partition
> tables grain level.
> Here is the code to reproduce the error:
> --start code
> drop view iv_T
> drop table t
> drop PARTITION SCHEME ps1
> drop PARTITION FUNCTION pf1
> go
>
Try this eqivilent formulation:
create view iv_T
with schemabinding
as
select description, sum(isnull(amt,0)) as amt, count_big(*) as rc
from dbo.t where description is not null
group by description
go
create unique clustered index ix_iv_t
on iv_T(description)
on [primary]
David|||Wow! I think I won the dummy of the year award... :)
That was it!
Do you realize how many hours I sat here trying to figure this out? Lets
just say Iâ'm on my 12 red bull and Iâ'm starting to get a sun burn from my
monitorâ?¦LOL.
Thanks David
Eric
"David Browne" wrote:
> "Eric" <Eric@.discussions.microsoft.com> wrote in message
> news:42E4A88F-66C6-4D3F-8BE5-254ECF59003C@.microsoft.com...
> > Sorry in addition, I have a calculation in my view that needs to be there
> > seeing that the view is being generated at a higher level then the
> > partition
> > tables grain level.
> >
> > Here is the code to reproduce the error:
> > --start code
> > drop view iv_T
> > drop table t
> > drop PARTITION SCHEME ps1
> > drop PARTITION FUNCTION pf1
> > go
> >
>
> Try this eqivilent formulation:
> create view iv_T
> with schemabinding
> as
> select description, sum(isnull(amt,0)) as amt, count_big(*) as rc
> from dbo.t where description is not null
> group by description
> go
> create unique clustered index ix_iv_t
> on iv_T(description)
> on [primary]
> David
>
>

No comments:

Post a Comment