In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-14 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
Today, I will talk to you about how Oracle triggers achieve the primary key self-increasing effect, which may not be well understood by many people. in order to make you understand better, the editor has summarized the following content for you. I hope you can get something according to this article.
The function of trigger
A trigger acts like an interceptor. Intercept some DML operations (insert/update/delete/select) against the database, and operate those that meet the business requirements. Operations that do not meet the requirements can be blocked by throwing an exception.
To put it bluntly, it is data confirmation (after) and security check (before). In addition, triggers are not targeted at select operations.
1. First create the table testUser
Oracle is set to be size-insensitive, so the table name is concise and concise.
CREATE TABLE testUser (id NUMBER (11) primary key, name VARCHAR (50)
two。 Create a sequence with a minimum of 1, a maximum of 99999999, an initial value of 1, and a step size of 1
Sequence name is customarily named for a certain table: seq_ table name
CREATE sequence seq_testUser minvalue 1 maxvalue 99999999 START WITH 1 INCREMENT BY 1 nocache ORDER
3. Create trigger
The trigger is based on sequence, so it is customary to name it: trg_sequence name
CREATE OR REPLACE TRIGGER trg_seq_testUser BEFORE INSERT ON testUser FOR EACH ROWBEGIN SELECT seq_testUser.nextval INTO: new.id FROM dual; END
4. Insert a piece of data
Insert into testUser (username) values ('Qiang 0'); insert into testUser (username) values ('Qiang 1'); insert into testUser (username) values ('Qiang 2')
5 query results
Select * from testUser after reading the above, do you have any further understanding of how Oracle triggers achieve the self-increasing effect of primary keys? If you want to know more knowledge or related content, please follow the industry information channel, thank you for your support.
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.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.