简体   繁体   中英

Creating SQL Trigger (insert or update) which will take data from one table and will put to another database table

I have got one table with name Links with fields

[PUBLICATION_ID],
[PAGE_ID],
[COMPONENT_ID],
[COMPONENT_TEMPLATE_ID],
[COMPONENT_TEMPLATE_PRIORITY],
[COMPONENT_POSITION],[URL]

in database Tridion_Broker

I want to create one SQL Trigger on insert/update which will take data from "Links" table for fields [PUBLICATION_ID], [URL] and put it to different database ( GoogleLinks ) and table MyLinks .

EDIT :
My Implementation is as below:

DROP TRIGGER IF EXISTS Update_Google_List;
DELIMITER $$
CREATE TRIGGER Update_Google_List AFTER INSERT , UPDATE 
    ON Tridion_Broker.dbo.Links
FOR EACH ROW 
BEGIN
INSERT INTO GoogleLinks.dbo.MyLinks (PUBLICATION_ID, URL)
SELECT DISTINCT PUBLICATION_ID as n,URL as u 
FROM Tridion_Broker.dbo.Links
WHERE Page_ID =@PageID 
AND Component_Template_Priority >0 
AND PUBLICATION_ID NOT IN(232,481) 
AND NOT EXISTS (SELECT 1 
FROM MyLinks as g 
WHERE g.PUBLICATION_ID = Links.PUBLICATION_ID
)
ORDER BY PUBLICATION_ID
END$$
DELIMITER ;

Creating a database item, modifying the database model, etc.. invalidates the support contract as far as I know.

I recommend you double check before proceed with this approach.

You can achieve the same scenario with a Deployer/Broker extension. In that case you write the linking information in a different table without touching the datamodel.

The Deployer/Broker extension is a supported scenario and works pretty well.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM