Re: [GENERAL] Add quto increment to existing column

2011-10-06 Thread Greg Williamson
Robert -- >Hi, > > >I have a column in a table called hist_id with the datatype "integer". When I >created the table I assigned this column the primary key constraint but didn´t >make it an auto-increment column. > > >How could I do this to an the already existing column? > > >I have created the

Re: [GENERAL] Add quto increment to existing column

2011-10-04 Thread Mark Watson
rt de Phil Couling Objet : Re: [GENERAL] Add quto increment to existing column Hi Dropping the column is a bit drastic if you already have data in there. You could just set the default on the column: alter table my_table alter hist_id set default nextval('hist_id_seq') Also considder

Re: [GENERAL] Add quto increment to existing column

2011-10-04 Thread Phil Couling
Hi Dropping the column is a bit drastic if you already have data in there. You could just set the default on the column: alter table my_table alter hist_id set default nextval('hist_id_seq') Also considder setting the sequence owner: alter sequence hist_id_seq owned by my_table.hist_id; This w

Re: [GENERAL] Add quto increment to existing column

2011-10-04 Thread marc_firth
If you use the SERIAL (this is the auto-incrementing function that creates sequences in the bankground for you) datatype you can accomplish it in one go. So: DROP sequence hist_id_seq; -- Get rid of your old sequence ALTER TABLE my_table DROP COLUMN hist_id; -- Remove id column ALTER TABLE my_t

[GENERAL] Add quto increment to existing column

2011-10-04 Thread Robert Buckley
Hi, I have a column in a table called hist_id with the datatype "integer". When I created the table I assigned this column the primary key constraint but didn´t make it an auto-increment column. How could I do this to an the already existing column? I have created the sequence with the followi