Oracle build table, and set the primary key self-added ____oracle

Source: Internet
Author: User

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 * *

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.