November 19, 2012 at 3:08 am
Good, easy question.
November 26, 2012 at 12:53 pm
What is the difference between option 1 and option 2? If option one would cause the default to be selected because that column will be null why doesn't manually setting it null cause the same thing?
November 26, 2012 at 1:11 pm
ScottC91 (11/26/2012)
What is the difference between option 1 and option 2? If option one would cause the default to be selected because that column will be null why doesn't manually setting it null cause the same thing?
Basically because you are inserting a value. Well the absence of a value really, but you are being specific about what you want in the field.
Look at it like this. In a nullable column without a user defined default, the default is actually NULL. If you insert a value, even NULL, you are telling SQL that you want that value in the field. If you don't pass in a value (or use the keyword DEFAULT) you are asking for the default.
Interestingly enough the following code will demonstrate this:
DECLARE @temp TABLE (temp int null)
INSERT INTO @temp VALUES (DEFAULT)
SELECT * FROM @temp
Note that I don't have a user defined default for the column temp, but when I use the DEFAULT keyword I get a null in the field.
Hope that helps.
Kenneth FisherI was once offered a wizards hat but it got in the way of my dunce cap.--------------------------------------------------------------------------------For better, quicker answers on T-SQL questions, click on the following... http://www.sqlservercentral.com/articles/Best+Practices/61537/[/url]For better answers on performance questions, click on the following... http://www.sqlservercentral.com/articles/SQLServerCentral/66909/[/url]Link to my Blog Post --> www.SQLStudies.com[/url]
November 28, 2012 at 10:18 am
Good and Easy One.
Thansk:hehe:
Viewing 4 posts - 31 through 33 (of 33 total)
You must be logged in to reply to this topic. Login to reply