Oracle Database auto-increment Field

Source: Internet
Author: User


When SQL Server is used, an auto-increment field is added and set as the primary key to avoid repeated records. Now let go of the advantages and disadvantages of doing so. Let alone implementation problems. When Oracle is used, this situation occurs. When a module is added, only one module name is input, and there is a module ID in the table. This ID is set to auto-increment. However, the field auto-increment function is not available in Oracle. However, this function can be implemented by writing sequences and triggers by yourself.
Www.2cto.com: the auto-increment function is used to automatically add and assign values to the auto-increment fields during insertion. Then we will create a sequence in Oracle and create a trigger so that at the time of insertion, the sequence increases by 1 and the auto-increment field is assigned a value. I use PL/SQL for visual creation. Create sequence: Name: sequence Name Min Value: Minimum count Max Value: maximum count Star with: Number of times Increment by: step Cache Size: Cache sequence specified Cache, oracle will prevent a set of specified size sequences in the memory in advance. After these sequences are used, the next group will be generated. This will make the access faster, but when the database is closed, and so on, the next re-generation of a sequence may interrupt the sequence, not the genetic continuous number. It is best to specify a sequence when it is not particularly required; if it is not filled in the Cache, the default settings will be used; when the Cache is set to 0 or nocache, a continuous sequence is generated. Cycle: the cyclic sequence. When the maximum value is reached, the Order starts from the minimum value. This ensures that the sequence generated and the request sequence are consistent. In parallel mode, if A and B request the sequence at the same time, the first-generation serial number must be returned to the First-requested user. This happens only on the oracle Parallel Server (not currently available). In most cases, it is needed in the lower part. Create a trigger at www.2cto.com: a statement-level trigger that does not contain the foreachrow clause in the CreateTrigger statement. A statement-Level Trigger can only trigger an event once and cannot be affected by the column values of each row of the trigger. It is generally used to process information about the SQL statements that trigger the trigger with the episode trigger-for example, who will execute the SQL statements and when to execute the SQL statements. A Row-level trigger that contains the ForEachRow clause in the CreateTrigger statement. A row-Level Trigger can be triggered on each row affected by the trigger, and can access the original column value and new column values processed through SQL statements. A typical application of a row-Level Trigger is to execute a transaction rule when you need to know the column value of a row. After confirmation, the following picture will appear
At www.2cto.com, You need to insert a select SEQ_MODEL.Nextval INTO: new. mdlID FROM dual between begin and end. I don't know if you have understood the above sentence carefully? If not, let's take a look at the values below. Supplement: 1) for the Insert statement, the values to be inserted must be included in new. column_name, where column_name is a column in the table 2) for the Update statement, the original value of the column is included in old_column_name, and the new value of the data column is new. column_name. 3) for the Delete statement, put the column value of the row to be deleted in old. column_name.
 

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.