Getting Default instead of GetDate() on insert snipet

Sushi21Sushi21 Posts: 1 New member
Hi,

I'm constantly getting into this annoying issue where my insert script generated by SQL prompt always write DEFAULT instead of the actual default being GetDate().

Some forums posts seems to tell that the GetDate() one should work


Sql prompt version : 10.11.9


Insert script produced

INSERT INTO Question.QuestionnaireType
(
    QuestionnaireTypeId,
    QuestionnaireTypeLabelID,
    CreatedBy,
    CreatedDate
)
VALUES
(   NULL,   -- QuestionnaireTypeId - PrimaryKeyConstant
    NULL,   -- QuestionnaireTypeLabelID - uniqueidentifier
    NULL,   -- CreatedBy - uniqueidentifier
    DEFAULT -- CreatedDate - datetime
    )

Tagged:

Answers

  • Kurt_MKurt_M Posts: 209 Silver 1
    Hi @Sushi21

    I did some testing myself on 10.11.11 and this appears to be the intended way the feature works when using the default values. I used your script as a basis and I set up a few other default values on the columns, and you'll notice they all pull through as default, not just the datetime field:




    However, if I change the CreatedDate column to remove the default value and instead add NOT NULL, then it generates GETDATE() in the values section:



    Depending on what way you choose to do it, it doesn't matter too much, as the GETDATE() value will be used when inserting.

    Hope that helps.


    Kind regards,

    Kurt McCormick
    Product Support Engineer, Redgate

    Need help? Take a look at our Help Center

Sign In or Register to comment.