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.
| Author |
Topic |
|
KingCarlos
Yak Posting Veteran
74 Posts |
Posted - 2011-01-12 : 20:33:49
|
| I am trying to write a trigger but failing miserably, what I want is a trigger to update a field in a table based on a value from another database.So I have data in the following place Database = DB1Table = Table1 Field = FieldAField – TBIDWhen FieldA changes I want it to update FieldX in the following databaseDatabase = DB2Table = Table1 Field = FieldXField – TBIDBoth records are linked together by the value in TBID so that is how the two will identify each other, any ideas welcomed, thanks |
|
|
dataguru1971
Master Smack Fu Yak Hacker
1464 Posts |
Posted - 2011-01-12 : 21:10:09
|
[code]Create table TableA (TBID int null, F1 int null)Create Table TableB (TBID int null, F1 int null)Insert into TableASelect 1,1Insert into TableBSelect 1,2GOCreate trigger tuA on TableAAFTER UPDATEASUpdate TableBSET F1 =inserted.F1FROM insertedWhere TableB.TBID = inserted.TBID GOSelect * FROM TableASelect * FROM TableBUpdate TableASet F1 = 3GOSelect * FROM TableASelect * FROM TableB[/code]That is the basics...you will have to test though...Triggers can be a nasty business sometimes. Poor planning on your part does not constitute an emergency on my part. |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2011-01-13 : 11:01:02
|
| for table in other db use dbname.schemaname.tablename in queries------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
|
|
|