Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.misc -> Re: How to add a primary key column

Re: How to add a primary key column

From: Daniel Morgan <damorgan_at_exxesolutions.com>
Date: Wed, 02 Jul 2003 08:44:27 -0700
Message-ID: <3F02FDDB.13F74ACD@exxesolutions.com>


Ralf Zwanziger wrote:

> I have a Table without a primary key and want to add a primary key.
> The problem is: how to update the existing columns with unique number
> values? I have the table with a column PK_Table and a sequence
> SEQ_Table. I thought the following statement would do it:
>
> Update Table set PK_Table = (select SEQ_Table.NextVal from dual)
>
> but this only results in ORA-02287: Sequence not allowed here.
> Any idea how to solve the problem, maybe with a cursor in PL/SQL?
>
> Thanks,
> Ralf

  1. Rename the table
  2. CREATE TABLE <original_table_name> AS SELECT sequence_name.NEXTVAL AS column_alias, field_name, field_name FROM renamed_table;
--
Daniel Morgan
http://www.outreach.washington.edu/extinfo/certprog/oad/oad_crs.asp
damorgan_at_x.washington.edu
(replace 'x' with a 'u' to reply)
Received on Wed Jul 02 2003 - 10:44:27 CDT

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US