Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Restart initial id of table with using MAX() method

Tags:

database

db2

I am doing some changes on my table and I couldn't figure out the problem. This is my SQL script;

ALTER TABLE X ALTER COLUMN X_ID RESTART WITH (SELECT MAX(X_ID) FROM X);

Altough I used AS instead of WITH and tried other combinations, I couldn't find the exact syntax. (By the way, I cannot set this property in the initialization, I got to do it after creation of the table )

like image 381
Kemal Toprak Uçar Avatar asked Sep 11 '25 10:09

Kemal Toprak Uçar


1 Answers

When looking at the syntax for ALTER TABLE you will find that you can only use a constant, e.g., "RESTART WITH 12345". A query itself is not possible. For automation you would need to break it up, use a variable, generate the ALTER statement and execute it.

like image 197
data_henrik Avatar answered Sep 13 '25 05:09

data_henrik