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

Home -> Community -> Usenet -> c.d.o.server -> Re: SQL question, updating all rows

Re: SQL question, updating all rows

From: Jonathan Gennick <gennick_at_worldnet.att.net>
Date: Wed, 17 Jun 1998 00:37:26 GMT
Message-ID: <6m733s$qt@bgtnsc03.worldnet.att.net>


On Mon, 15 Jun 1998 15:30:59 GMT, Zahi Al-Jamous <aljamous_at_crv.pechiney.fr> wrote:

>I have a table where I added a column, and I want this column to be
>the primary key of my table. I need then to update this column,
>adding a unique value for each row of my table.
>Can someone tell me how i can do this in SQL ?

Hmmm... You might be able to get away with this:

update table

        set pkey_field = rownum;

If that does'nt work, then this should definately work:

create sequence pkey_sequence;

update table

        set pkey_field = pkey_sequence.nextval;

Both of these should give you sequential numbers for your key field. After doing that, you need to add a primary key constraint, like this:

	ALTER TABLE xxx
		ADD (CONSTRAINT pk_xxx PRIMARY KEY (column_name));

regards,

Jonathan Received on Tue Jun 16 1998 - 19:37:26 CDT

Original text of this message

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