Skip to main contentSkip to solution

Which of the following is the correct syntax to modify the datatype of a given attribute in an existing table?

Solution

✅ Correct Option: 4

The correct syntax is ALTER TABLE tablename MODIFY attributename DATATYPE;\text{ALTER TABLE tablename MODIFY attributename DATATYPE;}

ALTER TABLE changes the structure of an existing table. The MODIFY clause then changes the datatype (or size) of an existing column, for example ALTER TABLE student MODIFY name VARCHAR(50);


Option 1: the keyword TABLE is missing, so the statement is invalid.

Option 2: ADD inserts a new column into the table. It does not change an existing column.

Option 3: EDIT is not a valid SQL clause.

In MySQL, the same task can also be written with CHANGE, which additionally renames the column.

Keyboard Shortcuts

  • Left arrow: Previous question
  • Right arrow: Next question
  • S key: Jump to solution
  • Q key: Jump to question