Questions tagged [database-sequence]

A database sequence is a number generator that produces unique numbers in a scalable and concurrency safe way.

A database sequence is a number generator that produces unique numbers in a scalable and concurrency safe way.

Once a sequence value has been generated, this number is never re-used (unless a sequence is defined to have a maximum value and cycle through its possible range).

Sequence values are not guaranteed to be gapless but offer a scalable and fast way to generate unique numbers even in high concurrency situations.

Sequences are supported by nearly all modern DBMS. However, the syntax to create them and to obtain a number from them differs between the DBMS products.

106 questions
0
votes
1 answer

Why does Azure SQL Database and MS SQL Server documentation say sequences are type sysname when they can be configured as anything?

I was looking at the examples and types while seeing how to use the SEQUENCE command in T-SQL (Azure SQL Database, SQL Server, etc.), but when it lists the types SEQUENCE can be configured as (INT, BIGINT, TINYINT, etc.), it mentions that its "type…
Netside
  • 80
  • 2
  • 9
0
votes
1 answer

What is the equivalent for NO ORDER of oracle sequence in postgresql?

I have a query CREATE SEQUENCE "SEQ_ID" MINVALUE 1 MAXVALUE 99999 INCREMENT BY 1 START WITH 121 CACHE 20 NOORDER NOCYCLE; This one is of oracle commands. Now, I want to convert into a PostgreSQL command. How do I…
Prajna
  • 129
  • 1
  • 8
0
votes
2 answers

I try to insert query alphanumeric sequence in table but it is not working

I am trying to insert an alphanumeric sequence in Oracle but it is not working. create sequence LIB start with 1 increment by 1; select 'LIBR'||to_char(seq_no.nextval,'FM0000099') from dual; create table addLib( USER_ID VARCHAR2(20) PRIMARY…
0
votes
3 answers

Oracle - How to rollback sequences inside multiple inserts

I have a script (that can fail) with multiple inserts that include nextval as insert into table a (id, value) (id_seq.nextval, 'value'); ... If script fails and I rollback the inserts, the sequence isn't rollback and multiple ids won't be in use Is…
Ori Marko
  • 56,308
  • 23
  • 131
  • 233
0
votes
2 answers

How to use sub-queries correctly inside a Postgresql query

I'm having troubles resetting the sequences as automatically as possible. I'm trying to use the next query from phpPgAdmin: SELECT SETVAL('course_subjects_seq', (SELECT MAX(subject_id) FROM course_subjects)); Somehow this query returns: > HINT: No…
an4rei
  • 57
  • 1
  • 7
0
votes
1 answer

How to update/increment an Oracle sequence by ten million?

I have a (Oracle) sequence that I use to assign an order number to new orders being inserted into a database table. It started at 1, and increments by 1 for each new order. I have a new requirement saying that order numbers should start at 10000000…
osullic
  • 543
  • 1
  • 8
  • 21
0
votes
1 answer

Cannot insert a number using SQL - whole column is removed / number is null

I'm trying to insert a Number as an ID in a column in my database by a loop which sets the new ID by a Sequence. When I try to insert it, the row hasn't been created or the field where my number should be is null. This only appears when I'm trying…
Silky
  • 53
  • 1
  • 8
0
votes
0 answers

Update unique id (start with 1)against the foreign key and unique id will again start with 1 the next foreign key

I need to update product_details table with unique ID(CHARGE_NUMBER) againt each batch_ID and for the next batch ID unique ID again will start with 1 I have write a code using sequence. update product_details set charge_number =…
0
votes
1 answer

How to change next default value for PostgreSQL sequence?

I have a table where the ID sequence goes like 01,02 and so on (I have a few pre-inserted values). When I try to insert a new row there (not specifying the ID explicitly, but rather values for other columns) it tells me that the default value is "1"…
Nikrango
  • 87
  • 2
  • 11
0
votes
2 answers

Auto Increment FK how does it update?

Ok so i am currently developing in Oracle 11G express edition for a college assignment. I have ran into an issue on how to auto increment and update in the following parent table. So i have an address table and then a city table for instance. Here…
0
votes
1 answer

Postgres: difference between DEFAULT in CREATE TABLE and ALTER TABLE in database dump

In database dump created with pg_dump, some tables have DEFAULTs in the CREATE TABLE statement, i.e.: CREATE TABLE test ( f1 integer DEFAULT nextval('test_f1_seq'::regclass) NOT NULL ); But others have an additional ALTER statement: ALTER TABLE…
Jarek
  • 329
  • 2
  • 13
0
votes
1 answer

Column ID skipped whenever it encounter a data duplicate

I have a table named email_recipients and an ID is skipped whenever there is a duplicate in email. CREATE TABLE email_recipients( id SERIAL PRIMARY KEY, email_address varchar(255) UNIQUE NOT NULL, last_name varchar(255), first_name…
Alex
  • 35
  • 1
  • 10
0
votes
1 answer

Implement a sequence that increments by value of a function

I am looking to create a simple sequence: CREATE SEQUENCE supplier_seq MINVALUE 1 START WITH 3 INCREMENT BY 4 CACHE 20000; However, I want to semi-randomize the incrementing values with a function determined by some factors implemented…
0
votes
1 answer

Need help .Problem with SQL Server nextval query

I have a problem with the SQL query- nextval in a SQL Server database: The multi-part identifier "applicationauth.nextvalue" could not be bound. Any idea what could be wrong? Here is query: insert into applicationauth (app, optionname,…
0
votes
2 answers

regarding Oracle PL SQL Loop

Doing some coding today. Encountered following problem with sequences. This code in PL/SQL: does not work as expected i.e. sequence is not incremented by 10 as I wanted - only by 1. This code: works fine. Sequence is incremented by 10 as…
mr thor
  • 13
  • 5