Member of the LearnItFirst.com Video Training Network | LearnSqlServer.com | SQL SSIS Training | SQL Programming Tutorials |
LearnSqlServer.com Forums LearnSqlServer.com
Welcome Guest Search | New Posts | Members | Log In | Register

Cannot use text, ntext, or image columns in the 'inserted' and 'deleted' tables. Options
ejoeyz_85
Posted: Sunday, February 03, 2008 9:50:01 AM
Rank: Newbie

Joined: 1/14/2008
Posts: 5
Points: 15
Location: Sg Buloh
i have created a trigger in my project... below is my trigger command

Quote:
CREATE TRIGGER Trg_UsersChangeAudit
ON Users
AFTER INSERT, UPDATE, DELETE
NOT FOR REPLICATION
AS
BEGIN
-- First make sure rows were actually affected
IF (@@ROWCOUNT > 0)
BEGIN
SET NOCOUNT ON;
DECLARE @inserted_count INT;
DECLARE @deleted_count INT;
SELECT @inserted_count = COUNT(*)
FROM inserted;
SELECT @deleted_count = COUNT(*)
FROM deleted;
-- First scenario: 1 or more rows inserted and
-- no deletes = INSERT statement
IF (@inserted_count > 0) AND (@deleted_count = 0)
BEGIN
INSERT INTO ActionLog (TableName,ActionType,ActionDML,UserID,ActionDate)
SELECT N'Users',
N'INSERT',
N'INSERT INTO Users (User_fname, User_address) ' +
N'VALUES (N''' + REPLACE(User_fname, N'''', N'''''') + N''', N''' +
REPLACE(User_address, N'''', N'''''') + N''');',
USER_NAME(),
CURRENT_TIMESTAMP
FROM inserted;
END
-- Second scenario: no inserted rows and
-- 1 or more rows deleted = DELETE statement
ELSE IF (@inserted_count = 0) AND (@deleted_count > 0)
BEGIN
INSERT INTO ActionLog (TableName,
ActionType,
ActionDML,
UserID,
ActionDate)
SELECT N'Users',
N'DELETE',
N'DELETE FROM Users ' +
N'WHERE User_fname = N''' + REPLACE(User_fname, N'''', N'''''') + N''';',
USER_NAME(),
CURRENT_TIMESTAMP
FROM deleted;
END
-- Third scenario: 1 or more inserted rows and
-- 1 or more deleted rows = UPDATE statement
ELSE IF (@inserted_count > 0) AND (@deleted_count > 0)
BEGIN
INSERT INTO ActionLog (TableName,
ActionType,
ActionDML,
UserID,
ActionDate)
SELECT N'Users',
N'UPDATE',
N'UPDATE Users ' +
N'User_fname = N''' + REPLACE(User_fname, N'''', N'''''') + N''', ' +
N'User_address = ''' + REPLACE(User_address, N'''', N'''''') +
N''' ' + N'WHERE User_application_id = ' +
CAST(User_application_id AS NVARCHAR(10)) + N';',
USER_NAME(),
CURRENT_TIMESTAMP
FROM inserted;
END
END
END;
GO




after execute this trigger, i got this message "Cannot use text, ntext, or image columns in the 'inserted' and 'deleted' tables." What shud i do to solve this problem....??? plzz reply me if someone know how to solve...
Scott Whigham
Posted: Tuesday, February 05, 2008 2:25:02 PM


Rank: Super Mod

Joined: 3/20/2006
Posts: 345
Points: 748
Location: Dallas, TX
Unfortunately text/ntext/image datatypes are not workable/allowed in triggers Frown No workaround
Users browsing this topic
Guest


Forum Jump
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.
     
Don't Forget!
LearnItFirst.com
Don't Forget!
LearnSqlServe.com
 
Home | About Us | Support | Contact Us | Privacy | Site Map | Blogs Blogs Refer a Friend and Get a Free Subscription!
© Copyright 2004-2007 LearnItFirst.com LLC. All rights reserved. All trademarks remain the property of their respective owners.
This site is not affiliated in any way with the Microsoft Corporation.