In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)06/01 Report--
The self-increasing primary key of oracle needs to be implemented by sequence and trigger.
Let's first create a table: the primary key is int to achieve self-increment.
CreatetableTEST
(
ID intPRIMARYKEY
Test1 varchar2 (20)
Test2 varchar2 (20)
Test3 varchar2 (20)
)
Create a sequence:
Create sequence SEQ_TEST
Minvalue 1-minimum
Maxvalue 9999999999999999999999999999999-maximum
Start with 1-start with 1
Increment by 1-add 1 at a time
Nocycle-- accumulate all the time, not cycle
Nocache
Create a trigger to increment the primary key when the data is inserted:
CREATE OR REPLACE TRIGGER tg_test
/ / test table name, id primary key name, seq_test.nextval sequence
BEFORE INSERT ON test
FOR EACH ROW WHEN (new.id is null)
Begin
Select seq_test.nextval into:new.id from dual
End
You can see that when the insert data primary key is empty, the sequence will be used to generate the self-increasing primary key.
/ /-trigger style
CREATE OR REPLACE TRIGGER TRI_SCORE
BEFORE INSERT OR UPDATE ON XUANKE
FOR EACH ROW
BEGIN
/ / if score is empty, make score=0
IF: new.SCORE IS NULL THEN: new.SCORE:= 0
END IF
END
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
$(".slider") .yxMobileSlider ({width:640,height:260,during:3000})
© 2024 shulou.com SLNews company. All rights reserved.