Auto Grow Field
When designing a database, it is sometimes necessary to automatically grow a field of a table, the primary key of the table is the most common use of the autogrow field, and the auto-grow field can simplify the generation of the primary key. There are different implementations of autogrow fields in different DBMS, as described below.
CREATE TABLE t_student (t_id int primary key auto_increment,t_name varchar (), t_age int);
Insert into t_student (t_name,t_age) VALUES ("King", "n"), insert into t_student (t_name,t_age) VALUES ("Hong", 22);
Unlike MySQL and MSSQLSERVER, Oracle does not specify an auto-Grow column, but the autogrow field can be implemented in Oracle through the sequence sequence.
Before using SEQUENCE, you need to first define a SEQUENCE, and the syntax for defining SEQUENCE is as follows:
CREATE SEQUENCE sequence_nameincrement by Stepstart with Startvalue;
Where Sequence_name is the name of the sequence, each sequence must have a unique name, the Startvalue parameter value is the starting number, and the step parameter value is the step size, which is the increment value for each auto-increment.
Once you have defined sequence, you can use currval to get the current value of sequence, or you can add sequence by Nextval , and then return a new sequence value, such as:
Sequence_name. Currvalsequence_name. Nextval
If the sequence is not needed, you can delete it:
DROP SEQUENCE Sequence_name;
Here is an example of using the sequence sequence to automate growth.
First create a sequence named Seq_personid:
Create sequence seq_t_personincrement by 1start with 1;
Then create the T_person table:
CREATE TABLE T_person (FId number PRIMARY KEY, FName VARCHAR2 (), Fage number (10));
After executing the above SQL statement, create a successful T_person table, and then execute the following SQL statement to
Insert some data into the T_person table:
INSERT into T_person (FID, FName, Fage) VALUES (seq_personid.nextval, ' Tom ', +); INSERT into T_person (FID, FName, Fage) VALUES (seq_personid.nextval, ' Jim ', Bayi); INSERT into T_person (FId, FName, Fage) VALUES (seq_personid.nextval, ' Kerry ') , 33);
Programmer's SQL Classic Note 1_ auto-grow field