New Oracle: creating self-growth fields similar to SQL Server

Source: Internet
Author: User

I have been using SQL Server for database development. Recently, I started to learn about oracle because I used Oracle databases for new projects.
After learning for a while, I found that there is still a big difference between SQL Server and Oracle. First, I couldn't find the self-growth field that I used very well in SQL Server in Oracle. My friend said that the sequence can be used. So I checked the data and sorted out the following example:

1. Create a test data table
Create Table Test
(
ID number,
Name varchar2 (20 ),
Primary Key (ID)
);

2. Create a sequence
Create sequence seq_test;

3. Create a trigger
Create or replace trigger autoincrement
Before insert on Test
For each row
When (New. ID is null)
Begin
Select seq_test.nextval into: New. ID from dual;
End;
/

4. insert data
Insert into test (name) values ('name1 ');

5. view the insert result
Select * from test;

 

 

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.