How to add a field to an Oracle database

Source: Internet
Author: User

It is mainly 2 points. First, createSequence;
Then, when the insert statement is run, the position of the auto-increment field is writtenSequence name. nextval.

The following describes how to create a table, then create a sequence, and write an insert statement to add a field.

1. Create a table first
 Create table "FLOWCAL "."T_USERINFO"
  ("C_ID"NUMBER (*, 0 ),
   "C_USER" VARCHAR2 (20 BYTE ),
   "C_PASSWORD" VARCHAR2 (20 BYTE ),
   "C_ROLE" VARCHAR2 (20 BYTE ),
   "C_COMMENT1" VARCHAR2 (20 BYTE ),
   "C_COMMENT2" VARCHAR2 (20 BYTE)
  )
Now I want to add C_ID.


2. Create an Oracle sequence. The SQL statement is as follows:
Create sequence name
Increment by 1
Start with 1
Max value 999999999
Cycle;
Create a sequence with a minimum value of 1 and a serial number with a maximum value of 999999999 to automatically cycle


Below is my sequence, as shown below:
CREATE SEQUENCE"FLOWCAL". "SEQ_USERINFO"
MINVALUE 0
Max value 9999999999999999999999999999
Increment by 1
Start with 24
CACHE 20
ORDER
CYCLE;
 
3. PassSequence name. nextvalDuring insertion, the Field Auto-increment is 1.
When inserting data into a table, the SQL statement is written as follows:
SQL>Insert into table name values (, column 1 value, column 2 value ,....);
"Sequence name" can be replaced with the name you need.

The following is my insert statement:
Insert into T_USERINFO values (SEQ_USERINFO.NEXTVAL, '11', '11', '11', '11', '11 ')

The following is an image for your reference:

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.