Permalink
Browse files

Get databases with compatibility level lower than instance

  • Loading branch information...
gboge committed Apr 10, 2017
1 parent 3a89003 commit 487eb7387571161451671c29e7f4b3483019bc84
Showing with 17 additions and 0 deletions.
  1. +17 −0 KServer.cs
View
@@ -67,6 +67,23 @@ public static DataTable ServiceStatus(this smo.Server s)
smo.Database d = s.Databases["master"];
return d.ExecuteWithResults(sql).Tables[0];
}
+
+ /// <summary>
+ /// Get databases with compatibility level lower than instance
+ /// </summary>
+ /// <param name="s">your smo server</param>
+ /// <returns>a datatable with the list of databases</returns>
+ public static DataTable DatabaseLowCompatibilityLevel(this smo.Server s)
+ {
+ int normalCompatibilityLevel = s.VersionMajor*10;
+ string sql = string.Format(@"SELECT name
+ , compatibility_level
+FROM sys.databases
+WHERE compatibility_level != {0}", normalCompatibilityLevel);
+ smo.Database d = s.Databases["master"];
+ return d.ExecuteWithResults(sql).Tables[0];
+ }
+
#endregion
#region SQL Server Versions

0 comments on commit 487eb73

Please sign in to comment.