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.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Triggers on a View

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2005-02-24 : 07:55:51
Iris writes "Do you know if I can create a trigger on a view? Whenever a record is inserted into a view, can I insert a new record into a table?
Actually, I tried the following scripts, but, it only works on a table, not on a view. I got error after running the following scripts:

{ Server: Msg 208, Level 16, State 4, Procedure userTrigger, Line 1
Invalid object name 'Userview'. }

I checked in sysobjects, it did exist.That’s why I donno what the problem is.

Do you know how to solve this problem? I attached my script in below for your reference.



CREATE TRIGGER userTrigger

ON Userview /* the name of the view */ /* If I put table name here, it works */

For Insert

AS

DECLARE @userID VARCHAR(11)
DECLARE @lastName VARCHAR(25)
DECLARE @Title VARCHAR(25)

SELECT @userID = (SELECT userID FROM Inserted)
select @LastName = 'NULL'
select @Title = 'NULL'


INSERT EmployeesTest values (@LastName,@userID,@Title)"

robvolk
Most Valuable Yak

15732 Posts

Posted - 2005-02-24 : 07:54:08
In SQL Server 2000, you can create INSTEAD OF triggers on views. Books Online has all the details under "CREATE TRIGGER".
Go to Top of Page
   

- Advertisement -