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
CreateTable test_increase (
userid number (10) primarykey, /* primary key, automatically add */
username varchar2 20 );
2 Creating an auto-grow sequence
CREATESEQUENCE testincrease_sequence
INCREMENTBy1--Add a few each time
STARTWith 1 -- count starting from 1
nomaxvalue -- does not set the maximum value
Nocycle -- has been accumulating, does not cycle
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/
Table in Oracle database set PRIMARY KEY auto-increment