1

Im using XAMP with mySQL and phpMyAdmin.

I cant seem to work out how to set a column to NOT NULL in php my admin..

How do i do this?

Is there a quick way to set all columns not to be null in mySQL?

I havve tried: ALTER TABLE flights CHANGE FlightID NOT NULL;

Thanks

1 Answer 1

2

You just need to issue an ALTER TABLE statement like this:

ALTER TABLE table_name
MODIFY column_name [data type] NOT NULL,
MODIFY column_name_2 [data type] NOT NULL,
...
MODIFY column_name_x [data type] NOT NULL

Note that [data type] here is of course the data type of your column (i.e. VARCHAR(255) or whatever)

Just list all the columns you want to modify in this single statement.

Sign up to request clarification or add additional context in comments.

5 Comments

Do you need to specify the datatype?
I get this error: "#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''flights' MODIFY 'FlightID' int(6) NOT NULL, MODIFY 'AircraftID' int(6) NOT ' at line 1"
@Lmc Yes you need to specify the data type
@LmC Don't use single quotes around your database object names (table name, column names). You should use backticks.
Ahhh sorry! Ill give it a try

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.