Adding a NOT_NULL constraint to an SQL column

I am trying to add a NOT_NULL constraint to a h2 SQL database column using

ALTER TABLE CHARACTERS ADD CONSTRAINT nn_PID NOT_NULL (PLAYER_ID); 

This follows the pattern I found here :

 ALTER TABLE Persons ADD CONSTRAINT pk_PersonID PRIMARY KEY (P_Id,LastName) 

Except, the names of constraints, tables, and columns are changed. But I get this error:

Syntax error in the SQL expression "ALTER TABLE CHARACTERS ADD CONSTRAINT NN_PID NOT_NULL [*] (PLAYER_ID)"; expected "., COMMENT, PRIMARY, INDEX, KEY, CHECK, UNIQUE, FOREIGN"; SQL statement: ALTER TABLE CHARACTERS ADD CONSTRAINT nn_PID NOT_NULL (PLAYER_ID) [42001-168] 42001/42001 (Help)

How to add NOT_NULL constraint?

+4
source share
1 answer

From H2 SQL Grammar :

 ALTER TABLE TEST ALTER COLUMN NAME SET NOT NULL; 

So we can use:

 ALTER TABLE CHARACTERS ALTER PLAYER_ID SET NOT NULL; 
+11
source

All Articles