Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Alter SQL table - allow NULL column value

Tags:

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?

like image 588
Klausos Klausos Avatar asked May 15 '12 09:05

Klausos Klausos


People also ask

How do I allow NULLs?

The allow NULLs option determines whether NULL values are permitted on the corresponding database field. Setting this option to no means a Not Null qualifier is included with this field in the generated DDL script. The default value for this option is dependent on the underlying data type of the field.

How do I assign a null value to a column?

You can use this query, to set the specific row on a specific column to null this way: Update myTable set MyColumn = NULL where Field = Condition. Here, the above code will set the specific cell to null as per the inner question (i.e. To clear the value from a cell and make it NULL).

Does SQL allow NULL values?

Using NULL values in your database is a permanent choice. Once you choose to allow them, you need to allow NULLs in all SQL database tables. Relational databases include NULLs by default, but they all let you reject NULLs should you decide to require developers to enter a value.


1 Answers

ALTER TABLE MyTable MODIFY Col3 varchar(20) NULL; 
like image 200
eggyal Avatar answered Oct 11 '22 15:10

eggyal