Derby如何在现有列上添加NOT NULL约束

huangapple go评论81阅读模式
英文:

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);

huangapple
  • 本文由 发表于 2020年8月25日 03:49:47
  • 转载请务必保留本文链接:https://go.coder-hub.com/63567827.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定