There is no self-increment field in Oracle, which can be implemented indirectly via sequence + trigger, Sqlplus login in cmd and run directly. It usually takes a few steps:
1 Creating a data sheet
CREATE TABLE Test_increase (
UserID Number PRIMARY KEY,/* primary key, auto increment */
Username VARCHAR2 (20)
);
2 Creating an auto-grow sequence
CREATE SEQUENCE testincrease_sequence
INCREMENT by 1--add a few each time
Start with 1-counting starting from 1
Nomaxvalue--Do not set the maximum value
Nocycle--keep accumulating, not looping
CACHE 10;
3 Creating a Trigger
CREATE TRIGGER Test_increase before
Insert on Test_increase for each ROW
Begin
Select Testincrease_sequence.nextval Into:New.userid from dual;
End
4 Submit
Commit
5 Testing
Execute the following statement repeatedly:
Insert into Test_increase (Username) VALUES (' Test ')
6 View Insert Results:
UserID username
1 Test
2 Test
3 Test
4 test
5 test
6 test
7 Test
8 test
9 test
Turn: Http://blog.163.com/[email protected]/blog/static/165190577201082910371842/
Oracle Set PRIMARY key auto-increment