|
|
|
SSChasing Mays
      
Group: General Forum Members
Last Login: Wednesday, February 20, 2013 1:45 AM
Points: 616,
Visits: 97
|
|
|
|
|
|
Forum Newbie
      
Group: General Forum Members
Last Login: Tuesday, February 26, 2013 2:27 PM
Points: 9,
Visits: 15
|
|
| 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?
|
|
|
|
|
Hall of Fame
       
Group: General Forum Members
Last Login: 2 days ago @ 7:53 PM
Points: 3,367,
Visits: 1,577
|
|
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 Fisher I strive to live in a world where a chicken can cross the road without being questioned about its motives. -------------------------------------------------------------------------------- For better, quicker answers on T-SQL questions, click on the following... http://www.sqlservercentral.com/articles/Best+Practices/61537/ For better answers on performance questions, click on the following... http://www.sqlservercentral.com/articles/SQLServerCentral/66909/
Link to my Blog Post --> www.SQLStudies.com
|
|
|
|
|
SSChasing Mays
      
Group: General Forum Members
Last Login: Monday, June 17, 2013 12:29 PM
Points: 606,
Visits: 138
|
|
Good and Easy One. Thansk
|
|
|
|