Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I modify a MySQL column to allow NULL?

Tags:

syntax

mysql

MySQL 5.0.45

What is the syntax to alter a table to allow a column to be null, alternately what's wrong with this:

ALTER mytable MODIFY mycolumn varchar(255) null; 

I interpreted the manual as just run the above and it would recreate the column, this time allowing null. The server is telling me I have syntactical errors. I just don't see them.

like image 765
zmf Avatar asked Oct 17 '08 16:10

zmf


People also ask

How do I change a column to allow NULL in MySQL?

Here is the syntax to allow NULL value. alter table yourTableName modify column yourColumnName datatype; Apply the above syntax to modify the column to allow NULL.

How do you change a column to allow NULL?

ALTER TABLE table_name ALTER COLUMN column_name DATA_TYPE [(COLUMN_SIZE)] NULL; In this syntax: First, specify the name of the table from which you want to change the column. Second, specify the column name with size which you want to change to allow NULL and then write NULL statement .

How do you fix a column that Cannot be NULL?

Using PHPMYADMIN you can go to the table, Clik on Structure and the under ACTIONS edit the column that is giving you trouble. Then select NULL and save: Or if you prefer coding it directly on a query add the following: ALTER TABLE table_name CHANGE column_name column_name type DEFAULT NULL.

How do I allow NULLs?

The allow NULLs option is only available for the details stereotyped attribute on an entity class. 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.


2 Answers

You want the following:

ALTER TABLE mytable MODIFY mycolumn VARCHAR(255); 

Columns are nullable by default. As long as the column is not declared UNIQUE or NOT NULL, there shouldn't be any problems.

like image 158
Daniel Spiewak Avatar answered Sep 19 '22 08:09

Daniel Spiewak


Your syntax error is caused by a missing "table" in the query

ALTER TABLE mytable MODIFY mycolumn varchar(255) null; 
like image 24
ConroyP Avatar answered Sep 17 '22 08:09

ConroyP