我已經在網上搜索和很多例子,但不能確定爲什麼我得到這個錯誤:無法插入到分區視圖
UNION ALL view 'devCascade_Gold1_hr.dbo.CustomAudit_View' is not updatable because a partitioning column was not found.
我上的,被設計的腳本動態創建多個表採取大量數據並將其推入分區視圖以更好地處理它。出於某種原因,我無法將數據插入視圖並獲得上述錯誤。
我已經檢查過看似一切。主鍵 - 檢查,不識別列 - 檢查。我插入表中,我正在測試的剋制好,但不是視圖。
下面是它的全部建成:
SET NOCOUNT ON
DECLARE @DataTabLabel as nvarchar(100), @sql as nvarchar(4000), @sqlView as nvarchar(max)
DECLARE @monthcount as tinyint, @filter as nvarchar(200), @droptext as nvarchar(80)
DECLARE @counter as int =1
DECLARE cur cursor for
select DISTINCT DataTabLabel from IntranetStdDataRequestCache
open cur
fetch next from cur into @DataTabLabel
IF OBJECT_ID ('dbo.CustomAudit_View', 'V') IS NOT NULL
DROP VIEW dbo. CustomAudit_View
SET @sqlView = 'CREATE VIEW CustomAudit_View AS
SELECT * FROM CustomAudit'+CAST(@counter as nvarchar(3))
while @@FETCH_STATUS = 0
BEGIN
SET @filter = 'datatablabel = ''' + @DataTabLabel + ''''
SET @droptext = 'DROP TABLE dbo.CustomAudit' + CAST(@counter as nvarchar(3))
IF OBJECT_ID ('dbo.CustomAudit'+CAST(@counter as nvarchar(3)), 'U') IS NOT NULL
EXEC sp_executesql @droptext
SET @sql = 'CREATE Table CustomAudit'+CAST(@counter as nvarchar(3)) +' (
layoutid bigint ,
displayemployeeid nvarchar (50) COLLATE database_default ,
forename nvarchar (50) COLLATE database_default ,
surname nvarchar (50) COLLATE database_default ,
datatablabel nvarchar (50) COLLATE database_default
CONSTRAINT CK_CustomAudit'+CAST(@counter as nvarchar(3))+' CHECK ('[email protected]+'),
requesteddatetime datetime,
username nvarchar (50) COLLATE database_default ,
updatelevel nvarchar (20) COLLATE database_default ,
updatetype nvarchar (20) COLLATE database_default ,
field nvarchar (50) COLLATE database_default ,
CurrentValue nvarchar (400) COLLATE database_default ,
Value nvarchar (400) COLLATE database_default ,
authorised nvarchar (20) COLLATE database_default ,
authoriserdatetime datetime ,
authemployeedesc nvarchar (100),
recruitment bit
CONSTRAINT PK_CustomAudit'+CAST(@counter as nvarchar(3))+' PRIMARY KEY CLUSTERED (displayemployeeid,datatablabel,requesteddatetime)
)
CREATE INDEX CustomAudit'+CAST(@counter as nvarchar(3))+'_AG ON CustomAudit'+CAST(@counter as nvarchar(3))+' (displayemployeeid, datatablabel) INCLUDE (field,requesteddatetime,username)
CREATE INDEX CustomAudit'+CAST(@counter as nvarchar(3))+'_empid ON CustomAudit'+CAST(@counter as nvarchar(3))+' (displayemployeeid)
CREATE INDEX CustomAudit'+CAST(@counter as nvarchar(3))+'_reqdate ON CustomAudit'+CAST(@counter as nvarchar(3))+' (requesteddatetime)'
EXEC sp_executesql @sql
PRINT 'dbo.CustomAudit'+CAST(@counter as nvarchar(3))+' Created'
PRINT 'Filter: ' + @filter
IF @counter <> 1
BEGIN
SET @sqlView = @sqlView + ' UNION ALL
SELECT * FROM ' + 'CustomAudit'+CAST(@counter as nvarchar(3))
END
SET @counter = @counter + 1
fetch next from cur into @DataTabLabel
END
IF OBJECT_ID ('dbo.CustomAudit_View', 'V') IS NOT NULL
DROP VIEW dbo. CustomAudit_View
EXEC sp_executesql @sqlView
PRINT 'CustomAudit_View Created'
close cur
Deallocate cur
SET NOCOUNT OFF
的表格罰款生成 - 他們的個人支票很好地工作。 該視圖還可以生成並可以毫無問題地查詢 - 即使執行計劃顯示它在嘗試獲取數據時僅使用正確的限制表。 在這裏提供答案的人贏得了我的內心和靈魂。
我甚至試圖消除日期字段,並再次產生這一切只是櫃面其時間戳的問題,我一直看到提到:
INSERT INTO CustomAudit_View
(layoutid , displayemployeeid, forename , surname , datatablabel, username,
updatelevel , updatetype, field , CurrentValue , Value, authorised , authemployeedesc, recruitment)
VALUES
(83921, 33134, 'Postponement',' One' ,'AUTO ENROLMENT', 'v', 'Direct','update' ,'IsMemberOfQualifyingPensionScheme',
0, 1 ,'N/A' , 'N/A', 0)
但都能跟得上 - 它仍然拒絕插入視圖。 我的表60是自動Enrolement唯一的一個設定爲約束所以現在林失去:
CustomAudit60 datatablabel ([datatablabel]='AUTO ENROLMENT')