0

I have a table named practice in which a column firstname is present and I'm trying to execute the following query.

alter table practice alter firstname not null ;

and I'm getting this syntax:

1064 - You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'varchar not null' at line 1

Need clarification on the syntax error.

MBijen
  • 317
  • 1
  • 13

2 Answers2

0

You have to specify a datatype and use Modify keyword when altering column in order to set the nullor not null parameter

Ex:

alter table practice modify firstname varchar(25) not null ;
Kobi
  • 2,494
  • 15
  • 30
0
ALTER TABLE practice MODIFY firstname varchar(64) NOT NULL;

A word of caution: you need to specify the full column definition again when using a MODIFY query. If your column has, for example, a DEFAULT value, or a column comment, you need to specify it in the MODIFY statement along with the data type and the NOT NULL, or it will be lost. The safest practice to guard against such mishaps is to copy the column definition from the output of a SHOW CREATE TABLE YourTable query, modify it to include the NOT NULL constraint, and paste it into your ALTER TABLE... MODIFY... query.

Reference : How to add not null constraint to existing column in MySQL5.1

Farhan Qasim
  • 990
  • 5
  • 18