CREATE DEFINER=`root`@`localhost` TRIGGER `change` AFTER INSERT ON `guest`
FOR EACH ROW 
update res set ResStatus=1  where res.ResNumber=inserted.ResNumber;
当对表guest插入一个数据时,表res的ResStatus变成1,可是这样写了之后,就无法插入数据了不知道为什么,求高人帮忙解答一下,是用navicat做的触发器,sql语句就是上面那样的

解决方案 »

  1.   

    update res set ResStatus=1  where res.ResNumber=new.ResNumber;
      

  2.   


    哦谢谢了,改完了果然可以了。另外再请教一下,如果用mysql做事务应用,应该怎么写?
    比如说我需要同时删除dishorder表里的ordernumber和drinksorder表里的ordernumber,应该怎样写?
    begin transaction;
    delete from dishorder where  ordernumber='$home';
    delete from drinksorder where  ordernumber='$home';
    commit;
    这样写对么?菜鸟不太会,麻烦你了
      

  3.   


    谢谢了哈~
    另外再请教一下,如果用mysql做事务应用,应该怎么写?
    比如说我需要同时删除dishorder表里的ordernumber和drinksorder表里的ordernumber,应该怎样写?
    begin transaction;
    delete from dishorder where  ordernumber='$home';
    delete from drinksorder where  ordernumber='$home';
    commit;
    这样写对么?菜鸟不太会,麻烦你了  
     
      

  4.   

    为什么不直接参考一下MYSQL的官方免费手册上的说明?
    12.4.1. START TRANSACTION, COMMIT, and ROLLBACK Syntax
    START TRANSACTION [WITH CONSISTENT SNAPSHOT] | BEGIN [WORK]
    COMMIT [WORK] [AND [NO] CHAIN] [[NO] RELEASE]
    ROLLBACK [WORK] [AND [NO] CHAIN] [[NO] RELEASE]
    SET autocommit = {0 | 1}The START TRANSACTION or BEGIN statement begins a new transaction. COMMIT commits the current transaction, making its changes permanent. ROLLBACK rolls back the current transaction, canceling its changes. The SET autocommit statement disables or enables the default autocommit mode for the current session. The optional WORK keyword is supported for COMMIT and ROLLBACK, as are the CHAIN and RELEASE clauses. CHAIN and RELEASE can be used for additional control over transaction completion. The value of the completion_type system variable determines the default completion behavior. See Section 5.1.4, “Server System Variables”. Note
    Within all stored programs (stored procedures and functions, triggers, and events), the parser treats BEGIN [WORK] as the beginning of a BEGIN ... END block. Begin a transaction in this context with START TRANSACTION instead. The AND CHAIN clause causes a new transaction to begin as soon as the current one ends, and the new transaction has the same isolation level as the just-terminated transaction. The RELEASE clause causes the server to disconnect the current client session after terminating the current transaction. Including the NO keyword suppresses CHAIN or RELEASE completion, which can be useful if the completion_type system variable is set to cause chaining or release completion by default. By default, MySQL runs with autocommit mode enabled. This means that as soon as you execute a statement that updates (modifies) a table, MySQL stores the update on disk to make it permanent. To disable autocommit mode, use the following statement: SET autocommit=0;After disabling autocommit mode by setting the autocommit variable to zero, changes to transaction-safe tables (such as those for InnoDB or NDBCLUSTER) are not made permanent immediately. You must use COMMIT to store your changes to disk or ROLLBACK to ignore the changes. To disable autocommit mode for a single series of statements, use the START TRANSACTION statement: START TRANSACTION;
    SELECT @A:=SUM(salary) FROM table1 WHERE type=1;
    UPDATE table2 SET summary=@A WHERE type=1;
    COMMIT;With START TRANSACTION, autocommit remains disabled until you end the transaction with COMMIT or ROLLBACK. The autocommit mode then reverts to its previous state. BEGIN and BEGIN WORK are supported as aliases of START TRANSACTION for initiating a transaction. START TRANSACTION is standard SQL syntax and is the recommended way to start an ad-hoc transaction. 
      

  5.   


    我是菜鸟,刚开始学..还都不太明白.真不好意思..我刚才输入了我写的那个事件应用,我用的navicat无法关闭数据库了..我按照之前论坛上讲的去找了一下错误日志..可是貌似都是正确的。
    一关闭就提示那个图片里的内容..还有就是错误日志里是这样的内容
    121216 23:06:20 [Note] D:\PHPnow-1.5.6\MySQL-5.1.50\bin\mysqld.exe: Normal shutdown121216 23:06:20 [Note] Event Scheduler: Purging the queue. 0 events
    121216 23:06:20  InnoDB: Starting shutdown...
    121216 23:06:24  InnoDB: Shutdown completed; log sequence number 0 659245
    121216 23:06:24 [Note] D:\PHPnow-1.5.6\MySQL-5.1.50\bin\mysqld.exe: Shutdown complete121216 23:06:26 [Note] Plugin 'FEDERATED' is disabled.
    121216 23:06:27  InnoDB: Started; log sequence number 0 659245
    121216 23:06:27 [Note] Event Scheduler: Loaded 0 events
    121216 23:06:27 [Note] D:\PHPnow-1.5.6\MySQL-5.1.50\bin\mysqld.exe: ready for connections.
    Version: '5.1.50-community-log'  socket: ''  port: 3306  MySQL Community Server (GPL)
      

  6.   

    学习的时候建议使用MYSQL自带的命令行工具。
    在一个贴子中请一次性把问题描述完整,不要解决一个又出现一个新问题。
      

  7.   

    你的代码是什么
    start transaction;
     delete from dishorder where  ordernumber='$home';
     delete from drinksorder where  ordernumber='$home';
     commit;