A recent definition I've read about Default Constraints:
DEFAULT is specified for a column to assign a column a specific value if no value is specified when a row is added.
I believe I've seen code written without the DEFAULT constraint specified and a NULL value was assigned to the field.
If I add a column to a table, do I have specify the DEFAULT keyword for the default value to be assigned? Or will NULL be assigned since I didn't delineate DEFAULT?
Best Answer
If your column definition does not have default constraint and it is nullable, the nullable field will have
null
mark, when you add a row even when you specifyDEFAULT
keyword for your insert value. For example for the following table definitionThe first three insert statements will insert NULL mark for ColB. Only the last one will have ColB value assigned.
Whereas for the following table definition with
DEFAULT
constraint.Only the second statement below will insert NULL mark for ColB. The first and the third statements will assign 'x' as the DEFAULT value.