function - subquery within alter table in db2 -
i want run subquery within alter table
command in db2.
alter table user alter column userid set generated identity (start 2646)
the above query works fine. want give start value query below.
alter table user alter column userid set generated identity (start (select max(userid) user))
i tried achieve using functions , stored procedures. problem table name should specified in both. want alter table query 40 tables.
create function findmax (tablename varchar(64), columnname varchar(255)) returns integer return select max(columnname) tablename
i have done before using sql scripts , doing multiple passes against database.
you can same if using findmax function if have sql this:
select 'findmax( ' || tabname || ' , ' || colname || ')' syscat.columns identity = 'y'
simply redirect output of sql text file , run text file sql.
you can directly alter table think you'd need 3 passes.
Comments
Post a Comment