Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 trigger

Author  Topic 

programer
Posting Yak Master

221 Posts

Posted - 2010-11-01 : 17:05:49
Hi,

I have two table:

Parent Table1:

Id, FirstName

Child Table2

Id, FirstName


In the Parent table FirstName data:
Joe
Mark

The child table FirstName data:
Mark
Joe
Joe
Joe

First table, column FirstName, data = Joe.


How to change data in seconed table, data = Joe.


Instead, Joe, I want Joey to another table.

How to change data in first table, column FirstName, data = Joe,

This is my trigger:

ALTER TRIGGER trg_YourTrigger ON dbo.Table1
FOR UPDATE
AS
UPDATE B.dbo.Table2
SET ColumnY = I.ColumnX
FROM inserted I
INNER JOIN
deleted D
ON I.ID = D.ID
WHERE B.dbo.BB.ColumnY = D.ColumnX


The first table I want to change the FirstName and writes this:

No row was updated

The data in row1 was not committed
Error Source: .Net SqlClient Data Provider.
Error Message: Invalid object name 'B.dbo.Table2.

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2010-11-01 : 20:15:00
[code]
UPDATE B.dbo.Table2
SET ColumnY = I.ColumnX
FROM inserted I
INNER JOIN
deleted D
ON I.ID = D.ID
WHERE B.dbo.BB.ColumnY = D.ColumnX[/code]

should that be Table2 instead of BB ?


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page
   

- Advertisement -