Oracle learning: Table creation and auto-increment of primary keys

Source: Internet
Author: User
The project has a need to store images to the database. You need to create a new table to take this opportunity to learn how to create an Oracle table and set the auto-increment of primary keys in the table.

The project has a need to store images to the database. You need to create a new table to take this opportunity to learn how to create an Oracle table and set the auto-increment of primary keys in the table.

The project has a need to store images to the database. You need to create a new table to take this opportunity to learn how to create an Oracle table and set the auto-increment of primary keys in the table.

First, create the tables required for the project:

Create table Device_Photo (
Device_PhotoID number (4) primary key,
Work_id number (10 ),
COL_115 varchar2 (20 ),
Photo1 blob,
Photo1_save_date date,
Photo2 blob,
Photo2_save_date date,
Photo3 blob,
Photo3_save_date date,
Photo4 blob,
Photo4_save_date date,
Photo5 blob,
Photo5_save_date date,
Create_date date,
Comments varchar2 (20)
);

Apart from the slightly different data types, the creation of Oracle tables is basically the same as that of SQL SERVER, which is relatively simple.

The following is a problem: Setting auto-increment for the primary key in Oracle. The implementation in SQL server is relatively simple, but Oracle does not provide similar methods. I checked the information, sequence is required to set auto-increment for primary keys in Oracle.
Sequence is a unique feature in Oracle that is used to generate a unique continuous sequence of numbers. The sequence is generally used as a primary key.


Create a sequence SEQ_Device_Photo

Create sequence SEQ_Device_Photo
Minvalue 1
Nomaxvalue
Start with 1
Increment by 1
Nocycle
Cache 20;

The usage and query results are as follows:

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.