1

I have a trigger with me and I want that which tables are being referenced by this trigger.Also same for Rules in sql server.I have a Rule in my db and I want the table name on which it is created. Also same for Indexes.

=========================EDIT===================

In case of following trigger Definition:

CREATE TRIGGER [dbo].[trgAfterInsert] ON dbo.[Employee_Test] 
FOR INSERT
AS
    declare @empid int;
    declare @empname varchar(100);
    declare @empsal decimal(10,2);
    declare @audit_action varchar(100);

    select @empid=i.Emp_ID from inserted i; 
    select @empname=i.Emp_Name from inserted i; 
    select @empsal=i.Emp_Sal from inserted i;   
    set @audit_action='Inserted Record -- After Insert Trigger.';

    insert into Employee_Test_Audit
           (Emp_ID,Emp_Name,Emp_Sal,Audit_Action,Audit_Timestamp) 
    values(@empid,@empname,@empsal,@audit_action,getdate());

    PRINT 'AFTER INSERT trigger fired.'
GO

In this case 2 tables should be shown as dependent table which are Employee_Test and Employee_Test_Audit.How can I get these names?

2 Answers 2

1

Try this one

SELECT OBJECT_NAME(parent_id) AS tablename, *
FROM [databasename].sys.triggers
Sign up to request clarification or add additional context in comments.

Comments

0

You can try the below code : "sp_depends trigger name" This will provide all details like stored procedure called and user tables referenced by the trigger.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.