why this condition fail (IF 1 <> 1)

  • Hi,

    I am confused about belwo statment.

    Although, Recovery model of TempDB can’t be changed but Why this simple IF condition fails?

    IF 1 <> 1

    BEGIN

    ALTER DATABASE TempDB SET RECOVERY SIMPLE WITH NO_WAIT

    END

    please help me

  • Because the validity of the statement is checked before it's actually run.

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass
  • If you really want, you can code it like that:

    IF 1 <> 1

    BEGIN

    EXEC ('ALTER DATABASE TempDB SET RECOVERY SIMPLE WITH NO_WAIT')

    END

    _____________________________________________
    "The only true wisdom is in knowing you know nothing"
    "O skol'ko nam otkrytiy chudnyh prevnosit microsofta duh!":-D
    (So many miracle inventions provided by MS to us...)

    How to post your question to get the best and quick help[/url]

  • @Gila

    Then why this code be executed successfully.

    IF 1 <> 1

    BEGIN

    BACKUP DATABASE tempdb TO DISK ='D:\tempdb.bak'

    END

  • I would guess because backup statements are checked for validity when they run. Two very different statements, you shouldn't be surprised they act differently (one's DDL the other maintenance)

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass
  • Thanks Gila

Viewing 6 posts - 1 through 5 (of 5 total)

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