In this case, the automatic growth column refers to the automatic growth of the primary key ID in a table.
Unlike MySQL, Oracle cannot set the automatic Growth column feature when create tables.
Oracle must create a sequence sequence to automate
In the development process, may use the Oracle sequence statement, this article takes the Oracle sequence statement how resets carries on the introduction, needs the friend to be possible to refer to under
Oracle Reset sequence Statement 1
SQL code
Preface:
People who have done web development basically know that the primary key value in a database table sometimes we use the numeric type
and the self increment. This makes it easy to use the tools to create tables in MySQL, SQL Server
. But
Oracle typically resets the sequence to initial 1 o'clock, which is deleted and rebuilt, which has many drawbacks, and the functions and stored procedures that depend on it will fail and need to be recompiled.
But there is a clever way, do not
Sequence: A database object provided by Oacle to produce a series of unique digits.
L provide a unique numeric value automatically
L Shared objects
L primarily used to provide primary key values
L Loading sequence values into memory can improve
The Oracle database uses that primary key generation strategy
1. Automatic Growth identity:
For MySQL, DB2, MS SQL Server, a database-generated primary key for generating unique identities for long, short, int types
Using the self-added fields of
Oracle self-Adding column creation method collection
Oracle does not have such features as the self-adding fields, but it can be implemented by triggers (trigger) and sequences (sequence).
First build a test table:
CREATE TABLE Userlogin(
ID
SQL Server1 Creating a TriggerGobeginif (object_id (' wmy ', ' tr ') is not null) DROP trigger wmyend; Gocreate TRIGGER Wmyon studentinstead of Insertasbegin INSERT into Student (number,name) VALUES (1205, ' role 2 '); End;--begin and end are
1. MySQL1) Build Tableauto_increment: The primary key ID of the Customer table (customers) is automatically increased by 1 per insert of data, as shown below 1 Create TableCustomers --Create a Customer table 2 (3IdintAuto_incrementPrimary Key not
First build the table:--Student Table (school number, name, gender, date of birth, grade, telephone, home address)CREATE TABLE Student (Stuno Number (5,0) primary key,--study No.Stuname VARCHAR2 (+) NOT NULL,--NameSex char (2) The default (' Male ')
Sequence: is a database object provided by Oacle to produce a series of unique numbers.
Automatically provide a unique value
Shared objects
Primarily used to provide primary key values
Loading
--Create sequence creation sequence sequence name start with 1--Start value increment by 1--increment maxvalue 99999999--Max Nocycle-If the maximum value is recalculated, the current is not recalculated and cycle is recalculated nocache; --do not
Create user Xianxian identified by Xianxian--dclGrant connect to Xianxian-Connect login roleGrant resource to Xianxian--resource operational Data permissionsGrant create any view to Xianxian--permissions to create views for usersMore than---Logged
The ID in sqlserver is set by the system. When we insert data, it will increase by itself, but oracle does not. We need to add the field ID by ourselves, because the ID is set to NOTNULL, the insert operation will fail, so you need to automatically
1. Avoid repeated primary keys when you want to retain the original data. Is it difficult to re-create a deleted sequence? This statement is much easier to use. Three parameters: order_sq is the sequence name. Order is the table name, and the
For the first time I learned to write the stored procedure, please give more comments and correct me. Thank you for your purpose: to insert NumInsert duplicate data from StartSerialNo to EndSerialNo to the table. The table only increments with the
Common Oracle SQL statements (1) preliminary understanding of insert delete update (DML) 1. INSERT (statement for inserting records INTO the data table) www.2cto.com A. INSERT data INTO the table: insert into Table Name (field name 1, field name 2 ,.
Oracle | PL/SQL sets auto-increment of primary keys. Oracle does not set auto-increment of primary keys. You need to set the sequence and trigger to auto-increment of primary keys. Example: create a table menu: [SQL] create table menu (menuId number
I. Data Control Statement (DML)
1. INSERT (INSERT the record statement into the data table)
Insert into Table Name (field name 1, field name 2 ,......) VALUES (value 1, value 2 ,......);Insert into Table Name (field name 1, field name 2 ,......)
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.