Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
drsloat
Starting Member
45 Posts |
Posted - 2009-04-23 : 15:09:19
|
| I'm working on Sql 2005 Standard Edition.I have set of tables with the data partitioned on an int column (SiteID) and a view (SubscriberDetail) that union all's these tables together.The SiteID in each table for the view has a constraint. Since i have the constraint, if i select from the view and include the value for the partition column (siteID), the query plan will only scan 1 table from the view.I was thinking that if i joined to the view from another table, and included the partition column this, query would also only scan 1 table. I can't seem to get this to work, however, unless my query explicity states the value for the partition column.I'm trying to write a query like the one that follows that does not scan all the indexes for the view tablesselect * from subscriber s, subscriberdetail dwhere s.subscriberid = d.subscriberIDand s.siteid = d.siteidand s.Subscriberid = 2CREATE TABLE [dbo].[Subscriber]( [SubscriberID] [int] NOT NULL, [SiteID] [int] NOT NULL, [Name] [varchar](50) NULL, CONSTRAINT [PK_Subscriber] PRIMARY KEY CLUSTERED ( [SubscriberID] ASC) ON [PRIMARY]) ON [PRIMARY]CREATE TABLE [dbo].[SubscriberDetail_100]( [SubscriberID] [int] NOT NULL, [SiteID] [int] NOT NULL, [Detail] [int] NULL, CONSTRAINT [PK_SubscriberDetail_100] PRIMARY KEY CLUSTERED ( [SubscriberID] ASC) ON [PRIMARY]) ON [PRIMARY]ALTER TABLE [dbo].[SubscriberDetail_100] WITH CHECK ADD CONSTRAINT [CK_SubscriberDetail_100] CHECK (([SiteID]=(100)))ALTER TABLE [dbo].[SubscriberDetail_100] CHECK CONSTRAINT [CK_SubscriberDetail_100]CREATE TABLE [dbo].[SubscriberDetail_200]( [SubscriberID] [int] NOT NULL, [SiteID] [int] NOT NULL, [Detail] [int] NULL, CONSTRAINT [PK_SubscriberDetail_200] PRIMARY KEY CLUSTERED ( [SubscriberID] ASC) ON [PRIMARY]) ON [PRIMARY]ALTER TABLE [dbo].[SubscriberDetail_200] WITH CHECK ADD CONSTRAINT [CK_SubscriberDetail_200] CHECK (([SiteID]=(200)))ALTER TABLE [dbo].[SubscriberDetail_200] CHECK CONSTRAINT [CK_SubscriberDetail_200]GoCREATE VIEW [dbo].[SubscriberDetail]ASSELECT SubscriberID, SiteID, DetailFROM dbo.SubscriberDetail_100UNION ALLSELECT SubscriberID, SiteID, DetailFROM dbo.SubscriberDetail_200Goinsert into SubscriberSelect 1, 100, 'test1'insert into SubscriberSelect 2, 100, 'test2'insert into Subscriberselect 3, 200, 'test3'insert into SubscriberDetail_100select 1, 100, 1insert into SubscriberDetail_100select 2, 100, 2insert into subscriberdetail_200select 3, 200, 3select * from subscriberselect * from subscriberdetail |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
|
|
|
|
|
|
|