Sequence is a database object from which multiple users may generate unique integers.
The topic learns how to:
In Database Explorer, right-click the Sequences folder, and then click New Sequence on the shortcut menu.
By default, dbForge Studio creates an ascending sequence that starts with 1, increments by 1, has 20 values cached (Oracle default), and is not limited.
To inspect the generated SQL query, click Script Changes. If you want to copy this scrpit to a clipboard, click Script Changes > To Clipboard.
-or-
On the Start Page, switch to the Database Design tab and click New Database Object.
In the New Object dialog box, select the Sequence type and then follow the steps from the procedure listed above.
-or-
On the Standard toolbar, click New Database Object and select the Sequence object type from the drop-down list and then follow the steps from the procedure listed above.
To create an Oracle sequence using the CREATE SEQUENCE statement, do the following:
On the Start Page > SQL Development tab, click SQL Editor.
-or-
On the Standard toolbar, click New SQL.
In the SQL editor, type the query. The syntax is as follows:
CREATE SEQUENCE schema_name.sequence_name
[INCREMENT BY interval]
[START WITH first_number]
[MAXVALUE max_value | NOMAXVALUE]
[MINVALUE min_value | NOMINVALUE]
[CYCLE | NOCYCLE]
[CACHE cache_size | NOCACHE]
[ORDER | NOORDER];
By default, dbForge Studio creates an ascending sequence that starts with 1, increments by 1, has 20 values cached (Oracle default), and is not limited.
Using the ALTER SEQUENCE statement, you can change the increment, minimum and maximum values, cache values, and behavior of a sequence object.
To change the attributes of the Oracle sequence using the ALTER SEQUENCE statement, do the following:
On the Start Page > SQL Development tab, click SQL Editor.
-or-
On the Standard toolbar, click New SQL.
In the SQL editor, type the query. The syntax is as follows:
ALTER SEQUENCE schema_name.sequence_name
[INCREMENT BY interval]
[MAXVALUE max_value | NOMAXVALUE]
[MINVALUE min_value | NOMINVALUE]
[CYCLE | NOCYCLE]
[CACHE cache_size | NOCACHE]
[ORDER | NOORDER];
If you want to start the sequence with a different number, you need to drop the sequence and then to re-create it by running the following query:
DROP SEQUENCE schema_name.sequence_name;
CREATE SEQUENCE schema_name.sequence_name
START WITH new_value;
To remove a sequence from the database, do the following:
On the Start Page > SQL Development tab, click SQL Editor.
-or-
On the Standard toolbar, click New SQL.
In the SQL editor, type the query. The syntax is as follows:
DROP SEQUENCE schema_name.sequence_name;
To remove a sequence in another schema, you should have the DROP ANY SEQUENCE privilege.