In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-31 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly explains "how to understand the trigger between two tables in java". The explanation in this article is simple and clear and easy to learn and understand. Please follow the editor's train of thought to study and learn "how to understand the trigger between two tables in java".
Create a trigger to increase the number of books borrowed / reduce the number of books returned.
When the books is updated by the lending attribute islend, the borrowing quantity amount is updated in the lender table at the same time, in which the updated islend attribute saves that id is the primary key in the id,lender of the borrower lender, and islend is the foreign key in the books table, connecting the two tables.
The structure of the two database tables is given below, and the triggers written are as follows:
CREATE TRIGGER `lendBook`After UPDATE ON `books`for EACH ROW BEGINUPDATE lenderSET amount = ifnull (lender.amount, 0) + 1WHERE id = new.isLend; INSERT INTO test (v1) VALUES (new.isLend); END
Test statement
Try {ps = conn.prepareStatement (sql); ps.setString (1, "1"); ps.setString (2, String.valueOf (bookId)); ps.setString (3, String.valueOf (id)); row = ps.executeUpdate ();} catch (SQLException e) {e.printStackTrace ();}
Can normally realize the function of borrowing / returning books and the function of trigger.
Thank you for your reading, the above is the content of "how to understand how to create a trigger between two tables in java". After the study of this article, I believe you have a deeper understanding of how to understand how to create a trigger between two tables in java, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.