我有2个具有相同列的表。我有一个触发器,可以在table_1
中将数据从table_2
添加到table_1
后插入table_1
。如何创建触发器,将更新的行从table_2
更新为import java.net.MalformedURLException;
import org.apache.xmlrpc.XmlRpcException;
import org.codehaus.swizzle.confluence.Page;
import org.xwiki.xmlrpc.XWikiXmlRpcClient;
public class UpdatePage {
public static void main(String[] args) throws MalformedURLException, XmlRpcException {
//URL of the xwiki instance
String url = "http://localhost:8080/xwiki/xmlrpc/confluence";
//Replace user & pass with desired xwiki username & password
String user = "Admin";
String pass = "admin";
XWikiXmlRpcClient rpc = new XWikiXmlRpcClient(url);
try {
//Perform Login & Authentication
rpc.login(user, pass);
//Create a Page object to hold our Document information
Page page = new Page();
//Fetch the required page. In our example, the page is in Space "demo code"
//and the Page is "Update Page"
page=rpc.getPage("demo code.Update Page");
//Fetch the content of the page & store it in a string for temporary storage
//This is the present content of the Page
String presentContent=page.getContent();
//Create a string that will hold the new content that is to be added to the Page
String newContent="\\\\Some new content added";
//Set the content of the page as: present content + new content
//However, this page is not yet stored to XWiki. It only resides in your application
page.setContent(presentContent+newContent);
//Finally, store the "updated" Page to XWiki
rpc.storePage(page);
//Just to make sure everything saved all right, fetch the content again for the Page
System.out.println(page.getContent());
} catch (XmlRpcException e) {
System.out.println("invalid username/password was specified or communication problem or ");
System.out.println(e);
} finally {
rpc.logout();
}
}
}
?
答案 0 :(得分:2)
我的说法与您AFTER INSERT
触发器的说法相同,只需指定AFTER UPDATE
:
delimiter //
CREATE TRIGGER tr_uau_table_1_table_2 AFTER UPDATE ON table_1
FOR EACH ROW
BEGIN
UPDATE `table_2`
SET `a` = NEW.a ,
`b` = NEW.b ,
WHERE `id` = OLD.id;
END;//
delimiter ;
(我没试过。)
MySQL文档:https://dev.mysql.com/doc/refman/5.7/en/trigger-syntax.html