Last answered:

08 Nov 2023

Posted on:

08 Nov 2023

0

Resolved: Does DROP DEFAULT => NOT NULL?

Whe I drop a default that is NULL does that imply that the field is now a NOT NULL field? 
Also, it looks like the default DEFAULT value is NULL when looking at the DDL.  So, we set the default value if we do not want the default to default to NULL, right?  



1 answers ( 1 marked as helpful)
Instructor
Posted on:

08 Nov 2023

0

Hi Sarah!
Thanks for reaching out.


Dropping a default constraint that is set to NULL does not make the field NOT NULL. The two properties—default value and nullability—are independent. If you want to ensure a field is not nullable, you must explicitly set it to NOT NULL. And yes, if you don't set a default value, SQL will use NULL as the default for nullable columns. To have a non-NULL default, you must explicitly set this when defining or altering the table.


Hope this helps.
Best,
Tsvetelin

Submit an answer