-1

How I can get the table which is affected by the query?

Example

Update cust
Set name = 'john'
Where custid = '4001'

Output:
cust

___________________________

Insert into emp(fname, lname)
Values('john', 'reyes')

Output:
emp


___________________________


Update cust
Set name = 'john'
Where custid = '4001'
Update emp
Set fname = 'rey'
Where fname = 'John'

Output:
cust, emp
1
  • 1
    What's your motivation? Are you profiling hotspots in your DB, or auditing or what? How do you hope to consume the responses? Jul 28, 2014 at 13:09

2 Answers 2

0

For your first example:

Update cust
Set name = 'john'
output 'cust'  
--, inserted.Name  -- optionally, uncomment this field as well, to get the Key of the updated record.
Where custid = '4001'
0

A trigger is an option to do this.

   create trigger ins_updt_trig 
    on cust 
    for update, insert
    as
    begin
    print 'cust'
    end

This will display a message when an update or insert occurs on 'cust' table. But I don't think this is a better option for a lot of tables because triggers are very difficult to manage.

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.