How to change the length of the Name column from CHAR(20) to CHAR(50)?


DB2 gives us an option of modifying the attribute of the existing column in a table. We have to use the ALTER COLUMN parameter with ALTER TABLE as below in order to achieve this.

ALTER TABLE DBSET1.TAB1
   ALTER COLUMN NAME
      SET DATATYPE CHAR(50);

The ALTER TABLE reserved words are followed by the name of the table qualified by a database, which is DBSET1.TAB1 in this case. Similarly, ALTER COLUMN is followed by the name of the column which needs to be modified, which NAME (of the student) in this case.

In the SET DATATYPE parameter, we can pass the new length 50 for the NAME column.

Updated on: 12-Sep-2020

102 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements