如何在 Firebird 2.5 中删除列的非空约束?
遗憾的是,这不起作用:
Alter table ESTOQUE_GRUPO_SUBELEMENTO ALTER column ID_SUBELEMENTO TYPE int null ;
最佳答案
在 Firebird 2.5 中,您无法使用 DDL 将 NOT NULL
约束添加到现有列,并且只能通过按名称删除约束来间接删除。 Firebird 3.0 中对此进行了更改(请参阅 Firebird 3.0 发行说明中的 Manage Nullability in Domains and Columns)。
NOT NULL
被实现为约束。如果您为其命名(或在系统表中查找生成的名称),则可以在 Firebird 2.5 中删除该约束。如 Firebird Null 指南 中的 Making non-nullable columns nullable again 部分所述.
删除它:
alter table Adventures drop constraint IdNotNull
(其中 IdNotNull
是 NOT NULL
约束的名称)
要查找约束的名称,您可以使用以下查询:
select rc.rdb$constraint_name from rdb$relation_constraints rc inner join rdb$check_constraints cc on rc.rdb$constraint_name = cc.rdb$constraint_name where rc.rdb$constraint_type = 'NOT NULL' and rc.rdb$relation_name = '<TableName>' and cc.rdb$trigger_name = '<FieldName>'
请参阅上面的链接了解更多详细信息。
在 Firebird 3.0 及更高版本中,您还可以使用
alter table table_name alter column_name drop not null
关于sql - 如何在 Firebird 2.5 中删除列的空约束,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/74477356/