|
Posted by ing42 on 03/14/06 13:12
I have a problem with inserting records into table when an indexed view
is based on it.
Table has text field (without it there is no problem, but I need it).
Here is a sample code:
USE test
GO
CREATE TABLE dbo.aTable (
[id] INT NOT NULL
, [text] TEXT NOT NULL
)
GO
CREATE VIEW dbo.aView
WITH SCHEMABINDING AS
SELECT [id]
, CAST([text] AS VARCHAR(8000)) [text]
FROM dbo.aTable
GO
CREATE TRIGGER dbo.aTrigger ON dbo.aView INSTEAD OF INSERT
AS
BEGIN
INSERT INTO aTable
SELECT [id], [text]
FROM inserted
END
GO
Do the insert into aTable (also through aView).
INSERT INTO dbo.aTable VALUES (1, 'a')
INSERT INTO dbo.aView VALUES (2, 'b')
Still do not have any problem. But when I need index on view
CREATE UNIQUE CLUSTERED INDEX [id] ON dbo.aView ([id])
GO
I get following error while inserting record into aTable:
-- Server: Msg 8626, Level 16, State 1, Procedure aTrigger, Line 4
-- Only text pointers are allowed in work tables, never text, ntext, or
image columns. The query processor produced a query plan that required
a text, ntext, or image column in a work table.
Does anyone know what causes the error?
Navigation:
[Reply to this message]
|