Edson Passos
Edson Passos

Reputation: 117

Is it OK to execute "ALTER TABLE ... MODIFY" without changing anything?

My application has a table with a VARCHAR(25), I need to increase that for old and new users.

For new users I can just update the CREATE statement. For old users I could execute "ALTER TABLE" on application startup.

At the moment I cannot know from what version the user is updating, so this leads to my question: Is it OK to execute that alter statement on every startup even if nothing is going to change or should I implement a way to check the previous version?

Upvotes: 0

Views: 1036

Answers (1)

slaakso
slaakso

Reputation: 9080

You can run the ALTER TABLE every time. If the column has already been changed previously, nothing happens.

Alternatively, you could check the column length before updating:

select CHARACTER_MAXIMUM_LENGTH
from INFORMATION_SCHEMA.COLUMNS
where TABLE_SCHEMA='db' and TABLE_NAME='table' and COLUMN_NAME='column'

Upvotes: 2

Related Questions