Hi,
I have a table that has been partitioned into a series of smaller tables for size & speed. The tables are partitioned by zip code into 100 tables. From what I understand, I should be able to generate a view that can present these tables as one, and thus eliminate the client-side 'use this table' logic. Accordingly, I should create check constraints on each table, build a view using UNION ALL for each table, and let the query optimizer remove all unnecessary select statements. I build the check constraints, write the sql, but when I access the view, the query times out. When I check the SQL with the Query Analyzer, it indicates that the other SELECT statements aren't being optimized away. Here's what I did specifically:
I created a check constraint for each table
using sql-dmo:
Dim svr As SQLDMO.sqlserver
Dim MyDb As SQLDMO.Database
Dim tbl As SQLDMO.Table
Dim Chk As SQLDMO.Check
Dim i As Integer
Set svr = New SQLDMO.sqlserver
svr.Connect "MYSERVER"
Set MyDb = svr.Databases.Item("DatabaseName"
For i = FIRST_TABLE To LAST_TABLE
Set tbl = MyDB.Tables.Item("tblZip" &
Format$(i, "00"
& "000"
Set Chk = New Check
With Chk
.Name = "Ck_" & tbl.Name
.Text = "([ZIP] >= " & i & "000 and [ZIP] < "& _
i+ 1 & "000)"
.ExcludeReplication = False
End With
tbl.Checks.Add Chk
Next
--This generated the check constraints, for example:
([ZIP] >= 12000 and [ZIP] < 13000) for tblZip12000
Then I created the view, which looked like:
CREATE VIEW VehiclesByZip AS
SELECT * FROM tblZIP00000
UNION ALL
SELECT * FROM tblZIP01000
UNION ALL
...
SELECT * FROM tblZIP99000
I then try to access the view with a stored procedure along
the lines of:
CREATE PROCEDURE [sp_VehiclesbyZip]
@zipcode int
AS
SELECT ZIP, MM FROM VehiclesByZip
WHERE ZIP = @zipcode
I've tried various modifications. Does the Developer Edition allow partitioned views? Any help would be helpful.
Thanks,
Don
I have a table that has been partitioned into a series of smaller tables for size & speed. The tables are partitioned by zip code into 100 tables. From what I understand, I should be able to generate a view that can present these tables as one, and thus eliminate the client-side 'use this table' logic. Accordingly, I should create check constraints on each table, build a view using UNION ALL for each table, and let the query optimizer remove all unnecessary select statements. I build the check constraints, write the sql, but when I access the view, the query times out. When I check the SQL with the Query Analyzer, it indicates that the other SELECT statements aren't being optimized away. Here's what I did specifically:
I created a check constraint for each table
using sql-dmo:
Dim svr As SQLDMO.sqlserver
Dim MyDb As SQLDMO.Database
Dim tbl As SQLDMO.Table
Dim Chk As SQLDMO.Check
Dim i As Integer
Set svr = New SQLDMO.sqlserver
svr.Connect "MYSERVER"
Set MyDb = svr.Databases.Item("DatabaseName"
For i = FIRST_TABLE To LAST_TABLE
Set tbl = MyDB.Tables.Item("tblZip" &
Format$(i, "00"
Set Chk = New Check
With Chk
.Name = "Ck_" & tbl.Name
.Text = "([ZIP] >= " & i & "000 and [ZIP] < "& _
i+ 1 & "000)"
.ExcludeReplication = False
End With
tbl.Checks.Add Chk
Next
--This generated the check constraints, for example:
([ZIP] >= 12000 and [ZIP] < 13000) for tblZip12000
Then I created the view, which looked like:
CREATE VIEW VehiclesByZip AS
SELECT * FROM tblZIP00000
UNION ALL
SELECT * FROM tblZIP01000
UNION ALL
...
SELECT * FROM tblZIP99000
I then try to access the view with a stored procedure along
the lines of:
CREATE PROCEDURE [sp_VehiclesbyZip]
@zipcode int
AS
SELECT ZIP, MM FROM VehiclesByZip
WHERE ZIP = @zipcode
I've tried various modifications. Does the Developer Edition allow partitioned views? Any help would be helpful.
Thanks,
Don