- Different Database Management Software
- Sql Trigger Update Different Database Management System
- Sql Server Database Level Triggers
- 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.
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 Mellado4 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.
So replace your current update
statement with
Different Database Management Software
Martin SmithYou 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
RichardTheKiwiRichardTheKiwiSql Trigger Update Different Database Management System
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.
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: