Question : Alter column with a parameter value.

How can I let this work?

ALTER TABLE MY_TABLE ALTER COLUMN ID RESTART WITH @ID

I need to give a parameter to restart this column id. But I get an error that it expect a numeric value.

I'm using this query with vs.net and DB2.

Thanks

Answer : Alter column with a parameter value.

Hi Nyhhyn,

The DB2 clients don't support the concept of "local variables" like SQL Server and Oracle do.  Hence the symbol @ID is an error to DB2.

Resetting an identity column starting point programmatically is an odd thing to do.  It's a bit dangerous and takes some measure of control away from DB2 and puts it into a generic program.

That said, you may be able to do it with a stored procedure.  The only obstacle is that DYNAMICRULES must be set for the package.

Below is a sample procedure that should be a good start.


Good Luck,
Kent
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
CREATE PROCEDURE reset_id_start (tablename varchar(32), columnname varchar (32), newstart integer)
...
BEGIN
  DECLARE command VARCHAR (200);
 
  SET command = 'ALTER TABLE "' || rtrim (tablename) || '" ALTER COLUMN "' ||
    rtrim (columnname) || '" RESTART WITH ' || DIGITS (newstart);
 
  EXECUTE IMMEDIATE command;
 
END;
Open in New Window Select All
Random Solutions  
 
programming4us programming4us