Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
![]() |
![]() |
Home -> Community -> Usenet -> c.d.o.misc -> Re: How to add a primary key column
Originally posted by Ralf Zwanziger
> 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
One way would be:
Update Table set PK_Table = ROWNUM;
Then set the sequence so that it continues from MAX(PK_Table)+1
-- Posted via http://dbforums.comReceived on Wed Jul 02 2003 - 04:14:09 CDT
![]() |
![]() |