Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add named not null constraint

Tags:

sql

mysql

I am trying to add a NOT NULL constraint by the name 'NN_Grade' in existing column 'grade'. but not able to do getting error -

My question is -

Add a constraint (NN_Grade) in table Empl that declares column Grade NOT NULL.

My Command which I tried-

ALTER TABLE students ADD CONSTRAINT NN_Grade NOT NULL(adm_no);

Error -

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 'NOT NULL(adm_no)' at line 1

Need guidance

like image 769
Vishal Avatar asked Jan 23 '26 11:01

Vishal


1 Answers

ALTER TABLE students ADD CONSTRAINT NN_Grade CHECK (adm_no IS NOT NULL);
like image 74
Ric Avatar answered Jan 25 '26 01:01

Ric



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!