Oracle creates an auto-increment primary key

Source: Internet
Author: User

Table creation:
The user must be displayed with the permission to create a trigger.
1. log on to sqlplus with sys/1234
2. In the command window, enter grant create any trigger to sprita1;
3. The message "Grant succeeded" indicates that the authorization is successful.

Create a table with an auto-increment primary key:
Create Table student
(
ID number not null primary key,
Name varchar2 (20) not null,
Gender varchar2 (20) not null,
Startdate date not null
);
// Comment
Comment on table student is 'student info table ';
Comment on column student. ID is 'id ';
Comment on column student. Name is 'name ';
Comment on column student. Gender is 'gender ';
Comment on column student. startdate is 'admission date ';
// Sequence
Create sequence st_sqc increment by 1;
// Trigger
Create or replace trigger std_tg_insert before insert on student for each row
Begin
Select st_sqc.nextval into: New. ID from SYS. Dual;
End;

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.