Oracle Create Primary Key Addendum Table of sql Statement Implementation and Trigger Application
- 2021-06-28 14:26:11
- OfStack
1. Create tables
2. Create an autogrowth sequence
3. Create triggers
4. Submit
5. Testing
insertinto
createtableTest_Increase(
useridnumber(10)NOTNULLprimarykey,/* Primary key, auto increase */
usernamevarchar2(20)
);
2. Create an autogrowth sequence
CREATESEQUENCETestIncrease_Sequence
INCREMENTBY1-- Add a few more at a time
STARTWITH1-- from 1 Start Count
NOMAXVALUE-- Set the maximum value without setting the maximum value: maxvalue9999
NOCYCLE--1 Direct accumulation, no cycle
CACHE10;
3. Create triggers
CREATETRIGGERTest_IncreaseBEFORE
insertONTest_IncreaseFOREACHROW/* For each 1 Row Detect Trigger */
begin
selectTestIncrease_Sequence.nextvalinto:New.useridfromdual;
end;
//* Sign out sqlplus Line Editing */
4. Submit
commit;
5. Testing
insertinto
Test_Increase(Username)values('test');