Sql Trigger Update Different Database Management

  1. Different Database Management Software
  2. Sql Trigger Update Different Database Management System
  3. Sql Server Database Level Triggers
  4. Different Database Management System

Server-scoped DDL triggers appear in the SQL Server Management Studio Object Explorer in the Triggers folder. This folder is located under the Server Objects folder. Database-scoped DDL Triggers appear in the Database Triggers folder. This folder is located under the Programmability folder of the corresponding database. Here Mudassar Ahmed Khan has explained with simple examples, how to write Insert, Update and Delete Triggers in SQL Server. This tutorial is applicable for all versions of SQL Server i.e. 2005, 2008, 2012, 2014, etc. TAGs: SQL Server. Triggers are database operations which are automatically performed when an action such as Insert, Update.

Active4 years, 9 months ago

I am new to triggers and want to create a trigger on an update of a column and update another table with that value.

I have table1 with a year column and if the application updates that year column I need to update table 2 with the year the same year.

Juan Mellado
14.2k5 gold badges40 silver badges51 bronze badges
Spafa9Sql Trigger Update Different Database ManagementSpafa9
3543 gold badges10 silver badges28 bronze badges

4 Answers

You don't reference table1 inside the trigger. Use the inserted pseudo table to get the 'after' values. Also remember that an update can affect multiple rows.

Management

So replace your current update statement with

Martin Smith

Different Database Management Software

TriggerMartin Smith
361k61 gold badges609 silver badges715 bronze badges

You only need to update the records in table2 if the column intannualyear is involved. Also, this is an alternative UPDATE syntax across two tables from what Martin has shown

RichardTheKiwiRichardTheKiwi

Sql Trigger Update Different Database Management System

89.9k23 gold badges163 silver badges236 bronze badges

According to this question, if there's only one 'downstream' table then another option with a properly defined foreign key relation would be Cascaded update.

Community
BilboBilbo

To supplement the above answers, if you have to check more than one column you can use a INNER JOIN between inserted and deleted, or several UPDATE() calls:

Sql Server Database Level Triggers

Z. KhullahZ. Khullah

Different Database Management System

Not the answer you're looking for? Browse other questions tagged sqlsql-server-2008triggerssql-update or ask your own question.