Reputation: 12584
I have a table which doesn't have an unique ID. I want to make a stored procedure which is adding to each row the number of the row as ID, but I don't know how to get the current row number. This is what I have done until now
CREATE OR ALTER PROCEDURE INSERTID_MYTABLE
returns (
cnt integer)
as
declare variable rnaml_count integer;
begin
/* Procedure Text */
Cnt = 1;
for select count(*) from MYTABLE r into:rnaml_count do
while (cnt <= rnaml_count) do
begin
update MYTABLE set id=:cnt
where :cnt = /*how should I get the rownumber here from select??*/
Cnt = Cnt + 1;
suspend;
end
end
Upvotes: 3
Views: 1862
Reputation: 4150
I think better way will be:
ID
).GEN_ID
).NEW.ID
is null
. Example.update table set ID = ID
. (This will populate the keys.)ID
column to not null.A bonus. The trigger can be left there, because it will generate the value in new inserted rows.
Upvotes: 5