dbTalk Databases Forums  

self join & indexed views

microsoft.public.sqlserver.server microsoft.public.sqlserver.server


Discuss self join & indexed views in the microsoft.public.sqlserver.server forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Kevin
 
Posts: n/a

Default self join & indexed views - 10-15-2003 , 05:07 PM






Does the following view have a "self join", and if not, why can't an indexed
view be created?

create table t1 (i int, j int)
create table t2 (i int)
go

create view v1 with SCHEMABINDING
as
select t1.i from
dbo.t1 join dbo.t2 on t1.i = t2.i join dbo.t2 t3 on t3.i=t1.i
go

create unique clustered index ci on v1(i)


--
Kevin Connell, MCDBA
--------------------------------------------------
The views expressed here are my own
and not of my employer.
----------------------------------------------------



Reply With Quote
  #2  
Old   
Tibor Karaszi
 
Posts: n/a

Default Re: self join & indexed views - 10-16-2003 , 01:37 AM






Yes, you have a self join. You specify the table t2 twice in the FROM clause, giving it different
alias names.

--
Tibor Karaszi, SQL Server MVP
Archive at: http://groups.google.com/groups?oi=djq&as ugroup=microsoft.public.sqlserver


"Kevin" <ReplyTo (AT) Newsgroups (DOT) only> wrote

Quote:
Does the following view have a "self join", and if not, why can't an indexed
view be created?

create table t1 (i int, j int)
create table t2 (i int)
go

create view v1 with SCHEMABINDING
as
select t1.i from
dbo.t1 join dbo.t2 on t1.i = t2.i join dbo.t2 t3 on t3.i=t1.i
go

create unique clustered index ci on v1(i)


--
Kevin Connell, MCDBA
--------------------------------------------------
The views expressed here are my own
and not of my employer.
----------------------------------------------------





Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.