Thread: Resetting sequence

Resetting sequence

From
"Keith Worthington"
Date:
Hi All,

In my database I have the following table with a serial column.  All of the
data has been deleted from the table.  I would like to know if the sequence
can be reset such that the next time a record is written into the table it
will have a value of 1.  TIA

# \d inventory.tbl_detail
   Table "inventory.tbl_detail"
     Column     |          Type          | Modifiers

----------------+------------------------+----------------------------
 inventory_id   | integer                | not null default
nextval('inventory.tbl_detail_inventory_id_seq'::text)
 inventory_date | date                   | not null
 inventory_type | character varying(20)  | not null
 note           | character varying(511) |
Indexes:
    "tbl_detail_pkey" PRIMARY KEY, btree (inventory_id)
Foreign-key constraints:
    "tbl_detail_fkey1" FOREIGN KEY (inventory_type) REFERENCES
inventory.tbl_type(inventory_type) ON UPDATE CASCADE ON DELETE RESTRICT


Kind Regards,
Keith

Re: Resetting sequence

From
Michael Fuhr
Date:
On Tue, Jan 25, 2005 at 05:19:41PM -0500, Keith Worthington wrote:

> I would like to know if the sequence can be reset such that the next
> time a record is written into the table it will have a value of 1.

See ALTER SEQUENCE and the "Sequence Manipulation Functions" section
in the "Functions and Operators" chapter in the documentation.

--
Michael Fuhr
http://www.fuhr.org/~mfuhr/