英文:
Derby how to add NOT NULL constraint on an existing column
问题
我一直在寻找解决方法,所看到的所有内容都不起作用,目前我正在尝试:ALTER TABLE INVOICE_RECORDS ALTER COLUMN SERIAL_NUMBER VARCHAR(10) NOT NULL
,但不起作用。
错误信息是:java.sql.SQLSyntaxErrorException: 语法错误:在第1行,第53列遇到了"VARCHAR"。
我正在一个 JavaFX 应用中运行这个。
我只想向 SERIAL_NUMBER 列添加 NOT NULL 约束。
英文:
I have been searching for solutions to this, all what I have seen doesn't work, currently I am trying: ALTER TABLE INVOICE_RECORDS ALTER COLUMN SERIAL_NUMBER VARCHAR(10) NOT NULL
but it doesn't work.
Error message is: java.sql.SQLSyntaxErrorException: Syntax error: Encountered "VARCHAR" at line 1, column 53.
I am running this in a JavaFX app.
I just want to add the NOT NULL constraint to the SERIAL_NUMBER column.
答案1
得分: 2
根据Bryan Pendleton的评论,我尝试了
ALTER TABLE INVOICE_RECORDS ALTER COLUMN SERIAL_NUMBER NOT NULL
...对我起作用。移除了 VARCHAR(10)
就解决了问题。
谢谢Bryan!
英文:
Based on Bryan Pendleton's comment I tried
ALTER TABLE INVOICE_RECORDS ALTER COLUMN SERIAL_NUMBER NOT NULL
...and it worked for me. Removing VARCHAR(10)
did the trick.
Thanks Bryan!
答案2
得分: 1
TutorialsPoint的说明如下:
ALTER TABLE INVOICE_RECORDS MODIFY SERIAL_NUMBER VARCHAR(10) NOT NULL
英文:
TutorialsPoint says to do it like this:
ALTER TABLE INVOICE_RECORDS MODIFY SERIAL_NUMBER VARCHAR(10) NOT NULL
答案3
得分: 0
尝试一下。
ALTER TABLE INVOICE_RECORDS ADD CONSTRAINT INVOICE_SERIAL_NUM NOT NULL(SERIAL_NUMBER);
英文:
Try this.
ALTER TABLE INVOICE_RECORDS ADD CONSTRAINT INVOICE_SERIAL_NUM NOT NULL(SERIAL_NUMBER);
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论