Defaults

  • Kenneth, thanks for the question. Everyone says back to basics question. Basically, it wasn't for me, as I've never even seen code (mine or anyone else's that used this.). Got it right, both here and in my head. 😉

    [font="Verdana"]Please don't go. The drones need you. They look up to you.[/font]
    Connect to me on LinkedIn

  • Hugo Kornelis (11/15/2012)


    Roland Alexander STL (11/15/2012)


    We ought to make note here that DEFAULT has been deprecated in an unspecified future version of SQL Server, so don't get too attached to it 🙂

    I think you are confusing default constraints (which are defined in the ANSI standard, and not deprecated) with "default objects" that can be bound to columns or alias data types.

    The ANSI standard DEFAULT constraint is what's used in this question - no seperate object, but a default definition used as a constraint in the table.

    The deprecated feature uses CREATE DEFAULT to create a default obejct, and then calls the stored procedure sp_binddefault to bind it to either a column or an alias data type.

    Reference (hyperlink!): CREATE DEFAULT

    No, I don't believe I'm confused. Have a look at the list at http://msdn.microsoft.com/en-us/library/ms143729.aspx where you'll find this entry:

    Use of DEFAULT keyword as default value.

    Do not use the word DEFAULT as a default value.

    under "Not Supported In A Future Version of SQL Server".

    Now, it may be that I misread this, but I'm hard-pressed to see how. Nonetheless I would be quite happy to be shown wrong.

    Roland Alexander 
    The Monday Morning DBA 
    There are two means of refuge from the miseries of life: music and cats. ~ Albert Schweitzer

  • Hugo Kornelis (11/15/2012)


    Roland Alexander STL (11/15/2012)


    We ought to make note here that DEFAULT has been deprecated in an unspecified future version of SQL Server, so don't get too attached to it 🙂

    I think you are confusing default constraints (which are defined in the ANSI standard, and not deprecated) with "default objects" that can be bound to columns or alias data types.

    The ANSI standard DEFAULT constraint is what's used in this question - no seperate object, but a default definition used as a constraint in the table.

    The deprecated feature uses CREATE DEFAULT to create a default obejct, and then calls the stored procedure sp_binddefault to bind it to either a column or an alias data type.

    Reference (hyperlink!): CREATE DEFAULT

    Re-reading the posts I realize I was not specific in what I said was deprecated. Default constraints are NOT deprecated, quite obviously, but using the DEFAULT keyword in an INSERT statement is deprecated. I apologize for the confusion and thank Hugo for pointing out the inadequacy.

    Roland Alexander 
    The Monday Morning DBA 
    There are two means of refuge from the miseries of life: music and cats. ~ Albert Schweitzer

  • I've never actually used the keyword DEFAULT before...seems kind of redundant. Oh well, I manage to apply logic to the other possible answers and derive that it must be a legit feature. Thanks for the 2 correct answers hint. 😎

    Aigle de Guerre!

  • Roland Alexander STL (11/15/2012)


    Hugo Kornelis (11/15/2012)


    Roland Alexander STL (11/15/2012)


    We ought to make note here that DEFAULT has been deprecated in an unspecified future version of SQL Server, so don't get too attached to it 🙂

    I think you are confusing default constraints (which are defined in the ANSI standard, and not deprecated) with "default objects" that can be bound to columns or alias data types.

    The ANSI standard DEFAULT constraint is what's used in this question - no seperate object, but a default definition used as a constraint in the table.

    The deprecated feature uses CREATE DEFAULT to create a default obejct, and then calls the stored procedure sp_binddefault to bind it to either a column or an alias data type.

    Reference (hyperlink!): CREATE DEFAULT

    Re-reading the posts I realize I was not specific in what I said was deprecated. Default constraints are NOT deprecated, quite obviously, but using the DEFAULT keyword in an INSERT statement is deprecated. I apologize for the confusion and thank Hugo for pointing out the inadequacy.

    I wonder if that means that the DEFAULT keyword won't work in updates either. If so I hope they replace the functionality with something else. We use it in some triggers to update a "lastupdate" column. UPDATE tablename SET columname = DEFAULT. I may be missing something but I can't see a way to do this without the DEFAULT keyword.

    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]

  • Good, easy question.

    Thanks

  • Roland Alexander STL (11/15/2012)


    No, I don't believe I'm confused. Have a look at the list at http://msdn.microsoft.com/en-us/library/ms143729.aspx where you'll find this entry:

    Use of DEFAULT keyword as default value.

    Do not use the word DEFAULT as a default value.

    under "Not Supported In A Future Version of SQL Server".

    Now, it may be that I misread this, but I'm hard-pressed to see how. Nonetheless I would be quite happy to be shown wrong.

    It toook me a lot of digging to get to the bottom of this. But finally, I stumbled upon a Connect item filed against this specific text in Books Online, back in 2007. Link: http://connect.microsoft.com/SQLServer/feedback/details/293052/incorrect-depreaction-use-of-default-keyword-as-default-value.

    Apparently, Microsoft wants to deprecate using the literal text 'DEFAULT' as a default value. Exactly why they want to do that is not clear, nor why, five years later, the wording has still not been clarified - but at least we can all heave a sigh of relief, knowing that Microsoft is not going to deprecate the ANSI-standard usage of syntax values. They are "only" going to outlaw one specific, randomly chosen value.

    (By the way, when thinking about this issue I can't help wondering what will happen in localized versions of SQL Server - will the Japanese version accept the string 'DEFAULT' but produce an error on the Japanese translation of that word? This looks like a very random idea to me!)


    Hugo Kornelis, SQL Server/Data Platform MVP (2006-2016)
    Visit my SQL Server blog: https://sqlserverfast.com/blog/
    SQL Server Execution Plan Reference: https://sqlserverfast.com/epr/

  • Nice question. I had never actually used the DEFAULT keyword in an insert statement before or seen it used. I have used default constraints many times but never considered doing something like;

    INSERT INTO #QOTD VALUES(1,DEFAULT) or UPDATE #QOTD SET WithDefault = DEFAULT.

  • Hugo Kornelis (11/15/2012)


    Roland Alexander STL (11/15/2012)


    No, I don't believe I'm confused. Have a look at the list at http://msdn.microsoft.com/en-us/library/ms143729.aspx where you'll find this entry:

    Use of DEFAULT keyword as default value.

    Do not use the word DEFAULT as a default value.

    under "Not Supported In A Future Version of SQL Server".

    Now, it may be that I misread this, but I'm hard-pressed to see how. Nonetheless I would be quite happy to be shown wrong.

    It toook me a lot of digging to get to the bottom of this. But finally, I stumbled upon a Connect item filed against this specific text in Books Online, back in 2007. Link: http://connect.microsoft.com/SQLServer/feedback/details/293052/incorrect-depreaction-use-of-default-keyword-as-default-value.

    Apparently, Microsoft wants to deprecate using the literal text 'DEFAULT' as a default value. Exactly why they want to do that is not clear, nor why, five years later, the wording has still not been clarified - but at least we can all heave a sigh of relief, knowing that Microsoft is not going to deprecate the ANSI-standard usage of syntax values. They are "only" going to outlaw one specific, randomly chosen value.

    (By the way, when thinking about this issue I can't help wondering what will happen in localized versions of SQL Server - will the Japanese version accept the string 'DEFAULT' but produce an error on the Japanese translation of that word? This looks like a very random idea to me!)

    LOL! Random is right! Thanks, Hugo, for digging into this and clearing the matter up. Much appreciated. I wonder why MS hasn't clarified the matter on the deprecation page...

    Roland Alexander 
    The Monday Morning DBA 
    There are two means of refuge from the miseries of life: music and cats. ~ Albert Schweitzer

  • Good basics question, nice and easy.

    Interesting discussion on the deprecation of 'DEFAULT' used as a default value; I can't imagine a more lunatic restriction myself, and I see Hugo's amusing question about the Japanese version as being relevant to just about every other language which is supprted for SQL Server.

    Tom

  • Thanks for an easy basics question, Ken!

  • Thanks for the question.

    Jason...AKA CirqueDeSQLeil
    _______________________________________________
    I have given a name to my pain...MCM SQL Server, MVP
    SQL RNNR
    Posting Performance Based Questions - Gail Shaw[/url]
    Learn Extended Events

  • Nice and easy afternoon question, here. 🙂

  • Great question, thanks Kenneth.

    Need an answer? No, you need a question
    My blog at https://sqlkover.com.
    MCSE Business Intelligence - Microsoft Data Platform MVP

  • ronmoses (11/15/2012)


    Dag-nabbit, that'll teach me to read more carefully. I read it as "how many" and not "which"! Duh. Well at least I got it right in my head. 😉

    Ron

    Ah, I'm not the only one 😀

    I was thinking: "why on earth are those checkboxes instead of a radio button?" 🙂

    Need an answer? No, you need a question
    My blog at https://sqlkover.com.
    MCSE Business Intelligence - Microsoft Data Platform MVP

Viewing 15 posts - 16 through 30 (of 33 total)

You must be logged in to reply to this topic. Login to reply