Alter SQL table - allow NULL column value

119,893

Solution 1

The following MySQL statement should modify your column to accept NULLs.

ALTER TABLE `MyTable`
ALTER COLUMN `Col3` varchar(20) DEFAULT NULL

Solution 2

ALTER TABLE MyTable MODIFY Col3 varchar(20) NULL;
Share:
119,893
Klausos Klausos
Author by

Klausos Klausos

Updated on July 09, 2022

Comments

  • Klausos Klausos
    Klausos Klausos almost 2 years

    Initially, the table "MyTable" has been defined in the following way:

    CREATE TABLE IF NOT EXISTS `MyTable` (
      `Col1` smallint(6) NOT NULL AUTO_INCREMENT,
      `Col2` smallint(6) DEFAULT NULL,
      `Col3` varchar(20) NOT NULL,
    );
    

    How to update it in such a way that the column "Col 3" would be allowed to be NULL?