Quantcast
Channel: Transact-SQL forum
Viewing all articles
Browse latest Browse all 23857

Getting an error 'sql server instead of triggers do not support direct recursion'.

$
0
0

Hi,

    I am getting the above error when i am trying to call an instead of insert triiger.

What i am doing is

1. I have a table EMPLOYEE.

2. Created a view on that table named 'EMPLOYEE_VIEW'

3. Created a trigger on this view (INSTEAD OF INSERT TRIGGER)

CREATE TRIGGER IO_TRG_INS_EMP_VW ON dbo.EMPLOYEE_VIEW
INSTEAD OF INSERT
NOT FOR REPLICATION 
AS
DECLARE @DB_NAME VARCHAR(20),@TABLE_NAME VARCHAR(20),@SCHEMA_NAME VARCHAR(20),@username varchar(200)
SELECT @DB_NAME = DB_NAME();
SELECT @username = SYSTEM_USER;
SET @TABLE_NAME = 'EMPLOYEE_VIEW';
SET @SCHEMA_NAME = 'dbo';
BEGIN
IF trigger_nestlevel() > 1
RETURN;

SELECT * INTO dbo.TEMP_EMPLOYEE_VIEW;

EXEC SAMPLE_INSERT @TABLE_NAME;
DROP TABLE dbo.TEMP_EMPLOYEE_VIEW;
END;
GO 

4. Now i am calling a procedure from this trigger for inserting the records.

CREATE PROCEDURE SAMPLE_INSERT @TABLE_NAME VARCHAR(50)
AS
DECLARE @QUERY NVARCHAR(4000);
BEGIN 
--SELECT NAME FROM dbo.TEMP_EMPLOYEE_VIEW;
SELECT @QUERY = 'INSERT INTO '+@TABLE_NAME+' SELECT * FROM dbo.TEMP_EMPLOYEE_VIEW';
PRINT @QUERY;
EXEC @QUERY;
END;

5. Everything is getting successfully, but when am doing an insert it is throwing the error.

What to do?



chaitanya ekre


Viewing all articles
Browse latest Browse all 23857

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>