简体   繁体   English

@@ SERVERNAME的SQL Server数据库阻止问题

[英]SQL Server database blocking issue with @@SERVERNAME

We have a locking issue on one of our database servers. 我们的一台数据库服务器上存在一个锁定问题。 After investigating in detail what is causing the blocking, we found out that this is one of our functions. 在详细调查造成阻塞的原因之后,我们发现这是我们的功能之一。 What was really surprising is that the function does nothing - just returns formatted server name. 真正令人惊讶的是,该函数不执行任何操作 -仅返回格式化的服务器名称。

CREATE FUNCTION [dbo].[GetReleaseName]()
RETURNS NVARCHAR(50)
AS
BEGIN   
    DECLARE @serverName NVARCHAR(20)
    DECLARE @ReleaseVersion NVARCHAR(20)

    SET @ReleaseVersion = '20170807'
    RETURN @@SERVERNAME + '_UAT_' + @ReleaseVersion
END

How can it be that @@SERVERNAME is causing any blocking? @@SERVERNAME怎么引起任何阻止?

Scalar functions have poor performance. 标量函数的性能较差。

Try replacing your function with an inline table valued function. 尝试用内联表值函数替换函数。

Here's an example: 这是一个例子:

CREATE FUNCTION [dbo].[GetReleaseName_ITVF]()
RETURNS TABLE
AS
RETURN(
    SELECT @@SERVERNAME + '_UAT_20170807' as FullServerName
)

Usage: 用法:

SELECT * FROM [table] CROSS APPLY GetReleaseName_ITVF()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM