是“执行”在本地编译的存储程序中必须进行强制性?

发布于 2025-01-25 11:15:01 字数 912 浏览 1 评论 0原文

我注意到,使用execute作为所有者定义了本质上编译存储过程(在SQL Server中)的所有示例(在SQL Server中)。

例如

CREATE PROCEDURE [dbo].[InsertOrderXTP]  
    @id INT, 
    @date DATETIME2, 
    @status TINYINT  
WITH NATIVE_COMPILATION, SCHEMABINDING, EXECUTE AS OWNER  
AS...

我们开始遇到以下错误,同时尝试执行使用执行为所有者的本质编译的存储过程:

无法获得有关Windows NT组/用户的信息...

这很有意义,因为我们与创建这些过程的用户还有其他无关的技术问题。

由于我们从未在常规(“解释”)过程中使用执行为..,因此我尝试将其从本质编译的存储过程中删除,并且似乎工作正常。

但是,正如我提到的,它与我见过的所有示例相比,我找不到在这个问题上详细阐述的任何相关文档。

  1. 使用执行为所有者...“??
  2. 必须 t定期(解释)存储程序存在

I noticed that all examples (that I've seen) of natively compiled stored procedures (in SQL Server) are defined using EXECUTE AS OWNER.

For example:

CREATE PROCEDURE [dbo].[InsertOrderXTP]  
    @id INT, 
    @date DATETIME2, 
    @status TINYINT  
WITH NATIVE_COMPILATION, SCHEMABINDING, EXECUTE AS OWNER  
AS...

We started getting the following error while trying to execute natively compiled stored procedures we created with EXECUTE AS OWNER:

Could not obtain information about Windows NT group/user ...

This make sense because we had other un-related technical issue with the user that created those procedures.

Since we never used EXECUTE AS .. in regular ("interpreted") procedures, I tried removing it from the natively compiled stored procedure and it seems to to be working just fine.

But as I mentioned, it contrast from all the examples I've seen, and I couldn't find any relevant documentation that elaborates on this issue.

  1. Must a natively compiled stored procedures be created with EXECUTE AS OWNER..."?
  2. Is there a benefit to creating natively compiled stored procedures with EXECUTE AS OWNER... that doesn't exist in regular (interpreted) stored procedures?
  3. Where can I find explicit documentation about this issue?

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

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

发布评论

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

评论(1

緦唸λ蓇 2025-02-01 11:15:01

这似乎是SQL Server 2016不再需要的历史限制

。 -transact-sql?view = sql-server-ver15#execute-as-clause“ rel =“ nofollow noreferrer”>创建过程的文档,我们有此注释:

对于启动SQL Server 2016(13.x)和Azure SQL数据库中的本质编译的存储过程,执行为子句没有限制。在SQL Server 2014(12.X)中,由本质编译的存储过程支持Self,所有者和“ USER_NAME”条款。

然后在关于执行为的单独页面是这样的:

呼叫者是除队列以外所有模块的默认值,并且与SQL Server 2005(9.x)行为相同。

将这两件事放在一起,我们发现在SQL Server 2014中本质上编译的存储过程中省略执行子句将默认为无支持的选项。因此,所有本质上编译的存储过程的示例均早于SQL Server 2016,将需要明确执行作为子句才能成功编译。

This appears to be a historical limitation that is no longer required as of SQL Server 2016.

In the documentation for CREATE PROCEDURE, we have this note:

For natively compiled stored procedures, starting SQL Server 2016 (13.x) and in Azure SQL Database, there are no limitations on the EXECUTE AS clause. In SQL Server 2014 (12.x) the SELF, OWNER, and 'user_name' clauses are supported with natively compiled stored procedures.

Then on the separate page about EXECUTE AS there is this:

CALLER is the default for all modules except queues, and is the same as SQL Server 2005 (9.x) behavior.

Put those two things together, and we find that omitting the EXECUTE AS clause on a natively compiled stored procedure in SQL Server 2014 would have defaulted to an unsupported option. So all examples of natively compiled stored procedures which predate SQL Server 2016 would have needed an explicit EXECUTE AS clause to compile successfully.

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