sql server - Syntax for SQL Trigger to Insert Data in another DB and also to update any field in another db adfter a field is edited -


here scenario - specific. have "bridged" db on sql called [fulcrum_xfer] use bridged because main db called [fulcrum uat] using bigint datatype fields , thereby displaying in access front end "#deleted data" in fields - behavior cannot changed in present design (the bigint has stay) have exact table name , fieldnames in [fulcrum_xfer] db - orderno field in orders table in [fulcrum_xfer] int , there no primary key

what need have done tomorrow under threat of "you let down" following

the table gets data inserted or updated called orders , in [fulcrum_xfer] database structure follows

orderno                int              unchecked orderdate              smalldatetime    unchecked applicationtenantlinkid int             unchecked orderstatus             int             unchecked 

the table receives triggered data orders in fulcrum_xfer called orders , in database fulcrum uat structure

orderno                bigint           unchecked  primarykey  orderdate              smalldatetime    unchecked applicationtenantlinkid bigint          unchecked orderstatus             int             unchecked 

i need 2 trigger statements insert new record orders in [fulcrum uat] after insert orders in [fulcrum_xfer]

and

i need trigger update field in orders in [fulcrum uat] when make change in orders in [fulcrum_xfer]

i not know trigger goes other maybe database triggers in [fulcrum_xfer] freaked out template syntax (do not think need that) , not know how write syntax each task

i experienced vb / vba developer , have used ado building , calling stored procedures on sql have never had type of task on sql server - please not treat me dunce - important in job right now.

well, of cousre have no way test it, think how you'd write insert trigger:

use [fulcrum_xfer] go set ansi_nulls on set quoted_identifier on go  create trigger dbo.trorders_insert     on  dbo.orders    after insert  begin     -- set nocount on added prevent result sets     -- interfering select statements.     set nocount on;      -- insert [inserted] pseudotable     --the target table     insert [fulcrum uat].dbo.orders                (orderno, orderdate, applicationtenantlinkid, orderstatus)         select orderno, orderdate, applicationtenantlinkid, orderstatus           inserted;  end go 

copy , paste query window in management studio , execute it.

here's how i'd update trigger. again, untested ...

use [fulcrum_xfer] go set ansi_nulls on set quoted_identifier on go  create trigger dbo.trorders_update     on  dbo.orders    after update  begin     -- set nocount on added prevent result sets     -- interfering select statements.     set nocount on;      -- update matching [inserted] pseudotable      --into target table     --(note: assumes updates never change pk/orderno)     update [fulcrum uat].dbo.orders          set orderdate   = ins.orderdate,              applicationtenantlinkid                         = ins.applicationtenantlinkid,              orderstatus = ins.orderstatus         [fulcrum uat].dbo.orders tar         join inserted ins on tar.orderno = ins.orderno;     --(also, performance may not great join columns      --  different datatypes) end go 

Comments

Popular posts from this blog

Magento/PHP - Get phones on all members in a customer group -

php - Bypass Geo Redirect for specific directories -

php - .htaccess mod_rewrite for dynamic url which has domain names -