3

I'm trying to alter the size of a field in my Java DB Database. I just can't seem to do it. My current data type is varchar(50) and I want to update it to varchar(150).

Brian Agnew
  • 268,207
  • 37
  • 334
  • 440
Josh Pritchard
  • 141
  • 1
  • 7

2 Answers2

8

Solved:

ALTER TABLE [table] ALTER COLUMN [column] SET DATA TYPE [type];

I wasn't using the SET DATA TYPE function and was instead just trying to redeclare it by using ALTER COLUMN [column] [type];

Brian Agnew
  • 268,207
  • 37
  • 334
  • 440
Josh Pritchard
  • 141
  • 1
  • 7
1

For mysql you can do this way

alter table table_name modify col_name varchar(150)

JDBC codes

PreparedStatement pt =connection.prepareStatement("alter table table_name modify col_name varchar(150)");
pt.executeUpdate();

In ms sql server use this command

ALTER TABLE [table_name]
ALTER COLUMN [Column_name] varchar(150)
SpringLearner
  • 13,738
  • 20
  • 78
  • 116