Create a table and auto-increment primary key in Oracle

Source: Internet
Author: User

Create a table in Oracle and an auto-increment table in primary key: create table tuser (id number (11) not null, name varchar2 (20) not null, password varchar2 (20), birthday date, constraint tuser_pk primary key (id); create sequence: create sequence increase_seq increment by 1 start with 1 nomaxvalue nocycle cache 10; create trigger: create or replace trigger tuser_triggerbefore insert on tuser for each rowbeginselect increase_seq.nextval into: new. id from dual; end; /According to the tool used, you may need to add "/" to execute PL/SQL blocks. Test: insert into tuser (name, password, birthday) values ('wujay ', '000000', null); commit; select * from tuser; id name password birthday ---------- -------------------- -------------- 1 wujay 123456 modify the table: alter table tuser rename column id to pk_tuser;

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.