ALTER DATABASE SET COMPATIBILITY_LEVEL runs irrespective of IF EXIST condition

  • Hi,

    Problem:

    I want to set compatibility_level only when it is greater than 110.

    Solution:

    Select the compatibility level and if it is greater than 110, I alter database set compatibility level=110

    ISSUE

    Irrespective of IF Exist statement the alter database statement is executed all the time.

    Here is the sql statement

    IF EXISTS (

    SELECT * FROM sys.databases where compatibility_level >110 AND name='mydatabase'

    )

    BEGIN

    ALTER DATABASE mydatabase SET COMPATIBILITY_LEVEL = 110

    END

    What is that I am missing here ??

    please support.

Viewing 0 posts

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