From: "Michel Cadot" <micadot@netcourrier.com>
Newsgroups: comp.databases.oracle.misc
Subject: Re: A tricky update...
Date: Wed, 6 Jun 2001 17:02:56 +0200
Organization: Guest of France Telecom Oleane's newsreading service
Lines: 101
Message-ID: <9flgn1$7dv$1@s1.read.news.oleane.net>
References: <5c5c8561.0106060646.15f1035@posting.google.com>
Reply-To: "Michel Cadot" <micadot@netcourrier.com>
NNTP-Posting-Host: 195.101.229.231
X-Trace: s1.read.news.oleane.net 991839777 7615 195.101.229.231 (6 Jun 2001 15:02:57 GMT)
X-Complaints-To: abuse@oleane.net
NNTP-Posting-Date: Wed, 6 Jun 2001 15:02:57 +0000 (UTC)
X-Newsreader: Microsoft Outlook Express 5.50.4522.1200
X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4522.1200


You can add a column to your table
then create a sequence and a trigger to populate it
and finaly make it a primary key.

Example:

v815> create table t (col number);
v815> insert into t values (0);
v815> /
v815> commit;
v815> select * from t;

       COL
----------
         0
         0

2 ligne(s) sélectionnée(s).

v815> alter table t add (id number);

Table modifiée.

v815> create sequence t_s;

Séquence créée.

v815>  create or replace trigger t_t
  2  before insert or update on t
  3  for each row
  4  begin
  5     if inserting then
  6        select t_s.nextval into :new.id from dual;
  7     else
  8        if :old.id is null then
  9           select t_s.nextval into :new.id from dual;
 10        end if;
 11     end if;
 12  end;
 13  /

Déclencheur créé.

v815> select * from t;

       COL         ID
---------- ----------
         0
         0

2 ligne(s) sélectionnée(s).

v815> update t set col=col;

2 ligne(s) mise(s) à jour.

v815> select * from t;

       COL         ID
---------- ----------
         0          1
         0          2

2 ligne(s) sélectionnée(s).

v815> insert into t (col) values (1);

1 ligne créée.

v815> select * from t;

       COL         ID
---------- ----------
         0          1
         0          2
         1          3

3 ligne(s) sélectionnée(s).

v815> alter table t add constraint pk_t primary key (id);

Table modifiée.

--
Hope this helps
Michel


"Benetnasch" <benetnasch@blimey.co.uk> a écrit dans le message news:
5c5c8561.0106060646.15f1035@posting.google.com...
> I have 2 rows in a table with exactly the information
> in them (badly designed, I know, but it's a legacy
> system). I need to update these rows so that a blank
> column is assigned a unique identifier. How can I
> run an SQL update on them to achieve this, please?
>
> Thanks for any information,
>
> Mark



