You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/docs/asciidoc/en/firebirddocs/nullguide/firebird-null-guide.adoc
+32-9Lines changed: 32 additions & 9 deletions
Original file line number
Diff line number
Diff line change
@@ -2085,6 +2085,18 @@ etc. -- see <<nullguide-add-check-not-null-field>>.
2085
2085
==== Removing a `NOT NULL` constraint
2086
2086
(((NOT NULL,remove)))
2087
2087
2088
+
In Firebird 3.0 and higher, you can drop a `NOT NULL` constraint from a table using:
2089
+
2090
+
[source]
2091
+
----
2092
+
alter table Adventures alter ID drop not null;
2093
+
----
2094
+
2095
+
If the `ID` column is based on a domain which also has a `NOT NULL` constraint, the column will still be constrained.
2096
+
You will need to drop the `NOT NULL` constraint from the domain as well to make the column really nullable, see the next section.
2097
+
2098
+
For Firebird 2.5 and earlier, dropping the `NOT NULL` constraint is more involved.
2099
+
2088
2100
If you gave the `NOT NULL` constraint a name when you created it, you can simply drop it:
2089
2101
2090
2102
[source]
@@ -2109,15 +2121,13 @@ where rc.rdb$constraint_type = 'NOT NULL'
2109
2121
and cc.rdb$trigger_name = '<FieldName>'
2110
2122
----
2111
2123
2112
-
Don't break your head over some of the table and field names in this statement;
2113
-
they are illogical but correct.
2114
-
Make sure to uppercase the names of your table and field if they were defined case-insensitively.
2124
+
Make sure to uppercase the names of your table and field if they were defined case-insensitively (that is, as a regular identifier).
2115
2125
Otherwise, match the case exactly but don't enclose the names in double-quotes like you would do in a regular query.
2116
2126
Also don't include the angle brackets (`<>`). Once you have the constraint name, you can drop it just like in the previous example.
2117
2127
2118
2128
[TIP]
2119
2129
====
2120
-
If the above statement returns an empty set and you are sure that you've correctly filled in the table and field names (including case!), and the constraint did not come from a domain either (this is discussed in the next sections), it may be that a third-party tool has made the column `NOT NULL` by setting a flag in a system table.
2130
+
If the above statement returns an empty set, and you are sure that you've correctly filled in the table and field names (including case!), and the constraint did not come from a domain either (this is discussed in the next sections), it may be that a third-party tool has made the column `NOT NULL` by setting a flag in a system table.
2121
2131
In that case it's probably best to remove it again with the same tool.
2122
2132
If that is not an option, check the field's `NULL` flag with:
2123
2133
@@ -2155,7 +2165,7 @@ However, before you can _insert_ ``NULL``s into the column, you must commit your
2155
2165
2156
2166
If the `NOT NULL` constraint came with a domain, it is not registered directly with the column.
2157
2167
This means you can't `DROP` it from the column either.
2158
-
Instead, change the column's type to a nullable domain or built-in data type:
2168
+
You can either drop it from the domain as well -- Firebird 3.0 and higher only -- or change the column's type to a nullable domain or built-in data type:
2159
2169
2160
2170
[source]
2161
2171
----
@@ -2244,7 +2254,19 @@ You must close all connections and reconnect before you can insert values that w
2244
2254
[[nullguide-change-domain-notnull]]
2245
2255
=== Altering a domain's `NOT NULL` setting[[d0e25188]]
2246
2256
2247
-
Once a domain is created, Firebird doesn't allow you to add or remove a `NOT NULL` constraint (`DROP CONSTRAINT` will only drop a `CHECK`).
2257
+
In Firebird 3.0 and higher, you can drop the `NOT NULL` constraint from a domain using:
2258
+
2259
+
[source]
2260
+
----
2261
+
alter domain MyDomain drop not null;
2262
+
----
2263
+
2264
+
[CAUTION]
2265
+
====
2266
+
Dropping the `NOT NULL` constraint from the domain affects all columns based on that domain, if they don't have an explicit `NOT NULL` constraint of their own.
2267
+
====
2268
+
2269
+
Firebird 2.5 and earlier don't allow you to add or remove a `NOT NULL` constraint from an existing domain (`DROP CONSTRAINT` will only drop a `CHECK`).
2248
2270
If you want to change a domain-wide `NOT NULL` setting, the official procedure is:
2249
2271
2250
2272
. Create a new domain with the desired characteristics.
@@ -2253,7 +2275,7 @@ If you want to change a domain-wide `NOT NULL` setting, the official procedure i
2253
2275
2254
2276
This is fine when it only concerns a few columns, but what if there are dozens or even hundreds?
2255
2277
It is possible to change the setting by going directly to the system table.
2256
-
Be aware however that Firebird does _not_ recommend or support this type of operation, nor is it guaranteed to keep working in future versions.
2278
+
Be aware however that Firebird does _not_ recommend or support this type of operation, and it is disallowed in Firebird 3.0 and higher.
2257
2279
That being said, it's a relatively simple operation and if properly executed it shouldn't cause you any problems.
2258
2280
2259
2281
So here's the SQL, but remember: at your own risk!
@@ -2270,7 +2292,7 @@ To remove a `NOT NULL` constraint, use `0` or `NULL`.
2270
2292
Write the domain name in all-caps if it was created case-insensitively;
2271
2293
otherwise, match the case exactly.
2272
2294
Don't use double-quotes and don't include the '```<>```'.
2273
-
Also note that, even when DDL autocommit is on (which is the default in `isql` and many other clients), this statement won't be autocommitted because technically it's not DDL.
2295
+
Also note that, even when DDL autocommit is on (which is the default in `isql` and many other clients), this statement won't be auto-committed because technically it's not DDL.
2274
2296
So don't forget to commit!
2275
2297
2276
2298
If you have set the flag to `1`, a subsequent `SHOW DOMAIN` will immediately report the domain as being `NOT NULL`.
@@ -2284,7 +2306,7 @@ If you have changed the flag from `1` to `0` or `NULL` -- making the domain null
2284
2306
But you still can't insert ``NULL``s in the columns, and any present ``NULL``s are still shown as zeroes (in most clients).
2285
2307
Close all connections and reconnect to straighten everything out.
2286
2308
2287
-
Lastly, please be warned again that this type of fiddling with the system tables is not recommended or supported by Firebird, and not guaranteed to keep working in future versions.
2309
+
Lastly, please be warned again that this type of fiddling with the system tables is not recommended or supported by Firebird, and no longer works in Firebird 3.0 and higher.
2288
2310
If the number of columns based on the domain is limited, it's better to switch them over to another domain or built-in type and then drop the old domain.
2289
2311
2290
2312
[[nullguide-testing]]
@@ -2757,6 +2779,7 @@ The exact file history is recorded in the firebird-documentation git repository;
2757
2779
|TBD
2758
2780
|MR
2759
2781
a|* Reordered revision history so most recent revision is at the top
2782
+
* Document Firebird 3.0 ability to drop not null constraints in _Making non-nullable columns nullable again_
0 commit comments