Полезная информация

next up previous contents index
Next: Primary and Foreign Keys Up: Unique Row Identifiers Previous: Sequences

Creating Sequences

Sequences are not automatically created like OIDs. You must use the CREATE SEQUENCE command to create them. Sequences are usually given names to match the table name. There are three functions that control access to sequence numbers. They are listed in table [*].

 
Table: Sequence number access functions
Function Action
nextval('name') Returns the next available sequence number, and updates the counter
curval('name') Returns the sequence number from the previous nextval() call
setval('name',newval) Sets the sequence number counter to the specified value


Figure [*] shows examples of sequence function use.
  
Figure: Examples of sequence function use
\begin{figure}\begin{list}{}{
\setlength{\rightmargin}{\leftmargin}
\raggedrigh...
... -{}-{}-{}-{}-{}-{}-{}-{}-
\par ~~~~~101
\par (1~row)\end{list}\par
\end{figure}

First, the sequence is created. Next, various sequence functions are called. Note the SELECTs do not have a FROM clause. The function calls are not directly tied to the customer table and do not access the customer table. Notice the nextval() function returns ever increasing values. Currval() shows the previous sequence value without incrementing it. Setval() sets the sequence counter to a new value.


next up previous contents index
Next: Primary and Foreign Keys Up: Unique Row Identifiers Previous: Sequences
Bruce Momjian
1999-11-21