1

Is there a difference between declaring a column with just Allow Nulls = Yes as compared to declaring it with both Default Value or Binding = NULL AND Allow Nulls = Yes?

In particular I'm interested in if there is a difference with respect to JDBC and the wasNull method semantics. My impression was that Allow Nulls = Yes (without a DEFAULT spec) was sufficient to allow you to exclude the column from an INSERT clause and expect that the value of that field in the inserted row is assigned the SQL NULL value...

It has been suggested to me that wasNull misbehaves for specifically for an NVARCHAR field in my database that is retrieved from a result set using the getString method of the result set when I didn't have the DEFAULT specified explicitly as NULL...

2 Answers 2

1

You can declare a column to have a default value of NULL, but it's a spectacularly pointless thing to do. All I'd expect it to achieve is to minutely slow down the insertion process (since it has to look up the default value). Allow Nulls = Yes should be sufficient.

I don't see how wasNull comes into this specifically, since, so far as I understand it, wasNull is used when consuming result sets, not when performing insert operations.

Sign up to request clarification or add additional context in comments.

7 Comments

Actually, depending on the data type, declaring the column to have a default value of NULL may be exactly what needs to be done.
@Michael - have you got an example you're thinking of?
@Damien: See the link in my answer.
(Obviously, that should be depending on the data type and the desired result.)
@Michael - there's no mention of requiring a default to achieve a null. The fourth bullet point says "Is nullable. A null value is used." - which would indicate that you don't need to do anything else to that column.
|
1

Simply making the column allow nulls does not guarantee that it will have the value NULL if it is not provided in an INSERT statement's column list.

Books Online has the gory details under the Arguments heading. Look at (column_list).

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.