您可以
STORED PROCEDURE在此上使用,因此您只能在应用程序级别调用一次。例子,
DELIMITER $$CREATE PROCEDURE InsertBook( IN _Title INT, IN _AwardName VARCHAr(35), IN _Year INT)BEGIN INSERT INTO Books (Title) VALUES(_Title); -- since the ID is set as AUTO_INCREMENT -- there are two ways to do how you can get the ID -- from the Books Table and insert it -- on BookAwards -- FIRST WAY -- by using LAST_INSERT_ID() SET @last_ID = LAST_INSERT_ID(); -- SECOND WAY -- by using MAX() -- SET @last_ID = (SELECt MAX(ID) FROM Books); INSERT INTO BookAwards(ID, AwardName, Year) VALUES (@last_ID, _AwardName, _Year);END $$DELIMITER ;
在应用程序级别或您要调用此过程的任何源上,
CALL InsertBook('Lost Art', 'Best in Churva', 2013);
为了安全起见,您仍然可以参数化该过程,例如
CALL InsertBook(?, ?, ?);
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)