I'm creating a new table, like this:
<createTable tableName="myTable">
<column name="key" type="int" autoIncrement="true">
<constraints primaryKey="true" primaryKeyName="PK_myTable" nullable="false"/>
</column>
<column name="name" type="nvarchar(40)">
<constraints nullable="false"/>
</column>
<column name="description" type="nvarchar(100)">
<constraints nullable="true"/>
</column>
</createTable>
As far as the nullable
constraint, if I omit that attribute what is the default setting?
E.g., If I only did this:
<column name="description" type="nvarchar(100)"/>
...would the column be nullable?
More importantly, where is the documentation that specifies this (as I have other questions like this)?
I looked here: Liquibase Column Tag, but it only says ambiguously:
nullable - Is column nullable?
It isn't documented, but I looked at the source code and it appears that if you do not specify, there is no constraint added to the column. One way you can check this yourself is to use the liquibase updateSql
command to look at the SQL generated.
Actually it's documented here.
Defines whether the column is nullable. Default: database-dependent
So the default null constraint is database-dependent. If you use Postgres, for example, it will be NOT nullable by default.
https://www.postgresqltutorial.com/postgresql-tutorial/postgresql-not-null-constraint/
Use the NOT NULL constraint for a column to enforce a column not accept NULL. By default, a column can hold NULL.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With