473,503 Members | 4,692 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Update Triggers to update another table in the DB

2 New Member
I am working on an update trigger that updates certain columns in table two when table one is updated.
Example If Column a, b, or c is updated in table 1, I need those to be updated in table 2- Column a, b, or c based on the unique identifier column (let's say column a in both tables are the ids). The other problem I have is that for both table there is also a colum D. In Table 1 column d can be = red, blue, or pink. If column d is = red or pink then column d in table 2 needs to be updated to red. If table 1, column d = blue, then column d in table 2 needs to be updated to blue.
Can someone please help me?
Dec 4 '08 #1
3 7547
ck9663
2,878 Recognized Expert Specialist
Can you post what you have so far?
Dec 5 '08 #2
tennytitansgeek
2 New Member
CREATE TRIGGER tr_u_employee ON employee
FOR UPDATE AS

DECLARE @a INT, @b INT, @C INT, @factor INT, @value INT, @columns AS VARCHAR(200), @colname AS VARCHAR(100)

IF ( (SUBSTRING(COLUMNS_UPDATED(),1,1) & 70 > 0))
AFTER UPDATE
ON Employee
FOR EACH ROW



-- Update record into Users table
UPDATE Portsl.dbo.Users
( employee_id,
FirstName,
LastName,
Status )
VALUES
( :old.employee_id,
:new.FirstName,
:new.LastName,
:new.Status );

END;
Dec 5 '08 #3
ck9663
2,878 Recognized Expert Specialist
On update trigger, get the old values from deleted and the new value from inserted tables. These are logical tables created during the update process and only accessible inside the trigger.

Happy coding!

-- CK
Dec 5 '08 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

7
248435
by: Dave | last post by:
I have 2 tables, one with names, and another with addresses, joined by their CIVICID number (unique to the ADDRESSINFO table) in Oracle. I need to update a field in the NAMEINFO table for a...
8
89290
by: Lauren Quantrell | last post by:
In VBA, I constructed the following to update all records in tblmyTable with each records in tblmyTableTEMP having the same UniqueID: UPDATE tblMyTable RIGHT JOIN tblMyTableTEMP ON...
1
6121
by: Gent | last post by:
am using FOR UPDATE triggers to audit a table that has 67 fields. My problem is that this slows down the system significantly. I have narrowed down the problem to the size (Lines of code) that need...
8
3294
by: Jan van Veldhuizen | last post by:
The UPDATE table FROM syntax is not supported by Oracle. I am looking for a syntax that is understood by both Oracle and SqlServer. Example: Table1: id name city ...
1
6286
by: Derek Erb | last post by:
SQL Server 2000 : I have a series of tables which all have the same structure. When any of these tables are modified I need to syncrhonise all of those modifications with one other table wich is a...
8
3750
by: Sean Shanny | last post by:
To all, The facts: PostgreSQL 7.4.0 running on BSD 5.1 on Dell 2650 with 4GB RAM, 5 SCSI drives in hardware RAID 0 configuration. Database size with indexes is currently 122GB. Schema for...
18
5934
by: Bill Smith | last post by:
The initial row is inserted with the colPartNum column containing a valid LIKE pattern, such as (without the single quotes) 'AB%DE'. I want to update the column value with the results of a query...
1
1540
by: rdraider | last post by:
Hi all, I know squat about triggers so was hoping somebody could point me in the right direction. I wanted to copy an email address field from a salesman table to a note field in a customer...
1
6190
by: abhi81 | last post by:
Hello All, I have a table on which I have created a insert,Update and a Delete trigger. All these triggers write a entry to another audit table with the unique key for each table and the timestamp....
1
1380
by: Microsoft Newsserver | last post by:
HI Im developing a solution in vs2005 with ajex extensions. Essentially I have three custom controls which render tables a representation as shown below. The problem is that when any of...
0
7207
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7093
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7291
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
7012
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7468
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
4690
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3171
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1522
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
402
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.