Adding the NOT_NULL constraint to an SQL column

时光毁灭记忆、已成空白 提交于 2019-12-22 07:05:19

问题


I'm trying to add the NOT_NULL constraint to a column in an SQL h2 database, 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 I change the constraint, table and column names. But I get this error:

Syntax error in SQL statement "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 can I add the NOT_NULL constraint?


回答1:


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;


来源:https://stackoverflow.com/questions/11672498/adding-the-not-null-constraint-to-an-sql-column

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!