如何确定SQL Server 2008或更高版本

发布于 2024-12-29 10:46:32 字数 90 浏览 1 评论 0原文

我需要以编程方式确定数据库是否支持地理数据类型和空间索引。这些功能是在 2008 年引入的。我还需要确定是否启用了 CLR,因为这些功能依赖于它。最可靠的方法是什么?

I need to determine programmatically if the database supports the Geography data type and Spatial indexes. These features were introduced in 2008. I also need to determine if CLR is enabled as these features rely on it. What is the most reliable way to do this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

冰火雁神 2025-01-05 10:46:32

SQL Server 2008 是 10.x

您可以在 SQL 和查询中使用 SERVERPROPERTY sys.configurations

SELECT
   PARSENAME(CAST(SERVERPROPERTY('ProductVersion') AS varchar(20)), 3) AS MajorVersion, 
   value_in_use
FROM 
   sys.configurations
WHERE
   name = 'clr enabled';

编辑:添加了CAST

SQL Server 2008 is 10.x

You can use SERVERPROPERTY in SQL and query sys.configurations

SELECT
   PARSENAME(CAST(SERVERPROPERTY('ProductVersion') AS varchar(20)), 3) AS MajorVersion, 
   value_in_use
FROM 
   sys.configurations
WHERE
   name = 'clr enabled';

Edit: added CAST

尘曦 2025-01-05 10:46:32

解析以下内容:

select @@VERSION

SELECT * FROM sys.configurations WHERE name = 'clr enabled'

SELECT compatibility_level from sys.databases where name=db_name()

如:

select
    CASE 
        WHEN LEFT(@@VERSION,25)='Microsoft SQL Server 2008' THEN 'Yes' 
        ELSE 'NO' 
    END AS OnSQLServer2008
    ,CASE value
         WHEN 0 THEN 'No'
         ELSE 'Yes'
     END AS [clr_enabled]
    ,(SELECT CASE compatibility_level WHEN 100 then 'Yes' ELSE 'No' END from sys.databases where name=db_name()) AS SQLServer2008CompatibilityMode
    FROM sys.configurations 
    WHERE name = 'clr enabled'

输出:

OnSQLServer2008 clr_enabled SQLServer2008CompatibilityMode
--------------- ----------- ------------------------------
Yes             No          No

(1 row(s) affected)

parse the following:

select @@VERSION

SELECT * FROM sys.configurations WHERE name = 'clr enabled'

SELECT compatibility_level from sys.databases where name=db_name()

like:

select
    CASE 
        WHEN LEFT(@@VERSION,25)='Microsoft SQL Server 2008' THEN 'Yes' 
        ELSE 'NO' 
    END AS OnSQLServer2008
    ,CASE value
         WHEN 0 THEN 'No'
         ELSE 'Yes'
     END AS [clr_enabled]
    ,(SELECT CASE compatibility_level WHEN 100 then 'Yes' ELSE 'No' END from sys.databases where name=db_name()) AS SQLServer2008CompatibilityMode
    FROM sys.configurations 
    WHERE name = 'clr enabled'

output:

OnSQLServer2008 clr_enabled SQLServer2008CompatibilityMode
--------------- ----------- ------------------------------
Yes             No          No

(1 row(s) affected)
长不大的小祸害 2025-01-05 10:46:32

您可以使用 SELECT @@VERSION 来返回相当详细的字符串。

更简单的方法是使用 This 返回一个数字来查看数据库兼容性级别

select compatibility_level from sys.databases where name=db_name()

。常见的值如下:

80 = SQL Server 2000

90 = SQL Server 2005

100 = SQL Server 2008

这样做的另一个好处是检查服务器上的数据库是否处于所需的级别,而不仅仅是检查服务器本身是否运行特定的系统版本。

You can use SELECT @@VERSION which returns a fairly verbose string.

Easier is to look at the DB compatibility level using

select compatibility_level from sys.databases where name=db_name()

This returns a numeric. Frequent values are such as:

80 = SQL Server 2000

90 = SQL Server 2005

100 = SQL Server 2008

This has the added benefit of checking that the database on the server is at the required level, not just that the server itself it running a particular system version.

下雨或天晴 2025-01-05 10:46:32

使用下面提到的查询

SELECT
SERVERPROPERTY('ProductVersion') AS ProductVersion,
SERVERPROPERTY('ProductLevel') AS ProductLevel,
SERVERPROPERTY('Edition') AS Edition,
SERVERPROPERTY('EngineEdition') AS EngineEdition;

来查找下面提到的版本。

在此处输入图像描述
在此处输入图像描述
在此处输入图像描述
在此处输入图像描述

Use the below mentioned query

SELECT
SERVERPROPERTY('ProductVersion') AS ProductVersion,
SERVERPROPERTY('ProductLevel') AS ProductLevel,
SERVERPROPERTY('Edition') AS Edition,
SERVERPROPERTY('EngineEdition') AS EngineEdition;

For the bellow mentioned Versions to find out.

enter image description here
enter image description here
enter image description here
enter image description here

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文