Oracle build table, and set the primary key to self increase
/*
Create a user table
*/
CREATE TABLE user_info_t (
ID integer NOT NULL,
user_id varchar (50),
User_name varchar (50),
User_password varchar (50),
User_sex varchar (20),
User_age Integer,
user_address varchar (50),
User_batch varchar (50),
Constraint USER_INFO_T_PK primary key (ID)
);
/*
Create a self-growth sequence
*/
Drop sequence dectuser_tb_seq; * * If the presence of the delete * *
Create sequence Dectuser_tb_seq MinValue 1 maxvalue 99999999
Increment by 1
Start with 1;
/*
Creating triggers
*/
Create or Replace Trigger Dectuser_tb_tri
Before insert on user_info_t/* Trigger condition: This trigger is triggered when an insert operation is performed on the table Dectuser.
For each row/* detects whether the trigger/
Begin/* Trigger Start * *
Select Dectuser_tb_seq.nextval into:new.id from dual; /* Trigger subject content, that is, the action to be executed after the trigger, where the next value of the get sequence dectuser_tb_seq is inserted into the ID field in the table user_info_t.
End
/*
Submit
*/
Commit
/*
Test
*/
Insert into user_info_t (user_id,user_name,user_password,user_sex,user_age) VALUES (' Warren ', ' Stone ', ' Warren ', ' M ', 22) /* Insert Test value * *
SELECT * FROM user_info_t/* Inquiry * *