Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Alter Database Runs Irrespective of Is Exist Condi

Author  Topic 

gokula_k
Starting Member

3 Posts

Posted - 2015-03-05 : 22:31:46
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.

robvolk
Most Valuable Yak

15732 Posts

Posted - 2015-03-06 : 07:19:45
Please do not cross post:

http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=200146
Go to Top of Page
   

- Advertisement -