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

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | Active Topics | Members | Search | Forum FAQ
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 Script Library
 Alter Database Runs Irrespective of Is Exist Condi
 Topic Locked
 Printer Friendly
Author Previous Topic Topic Next Topic  

gokula_k
Starting Member

3 Posts

Posted - 03/05/2015 :  22:29:56  Show Profile
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

USA
15732 Posts

Posted - 03/06/2015 :  07:20:06  Show Profile  Visit robvolk's Homepage
Please do not cross post:

http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=200146
Go to Top of Page
  Previous Topic Topic Next Topic  
 Topic Locked
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.02 seconds. Powered By: Snitz Forums 2000