Stored Procedure argument quot;NULLquot; or quot;= NULLquot;(存储过程参数“NULL或“= NULL)
问题描述
有什么区别:
CREATE PROCEDURE [dbo].[MyProcedure]
@MyArgument INT NULL
和
CREATE PROCEDURE [dbo].[MyProcedure]
@MyArgument INT = NULL
我使用了第一个,它在 SQL Server 2016 中运行良好.但 SQL Server 2012 不接受它.两者都适用于 SQL Server 2016,我现在使用第二个没有问题.但了解其中的差异会很有趣.
I used the first one, and it worked fine in SQL Server 2016. But SQL Server 2012 did not accept it. Both works on SQL Server 2016, and I am using the second one now without problem. But it would be interesting to know the difference.
谢谢!
推荐答案
他们不做同样的事情.第二个为调用者未指定的情况定义默认值.第一个没有.
They don't do the same thing. The second one defines a default value for the case that the caller doesn't specify one. The first one doesn't.
本机编译存储过程的 Transact-SQL 语法"grammar 允许将参数数据类型声明为允许 NULL
或 NOT NULL
.这是为 Hekaton(内存优化表)引入的.
The "Transact-SQL Syntax for Natively Compiled Stored Procedures" grammar allows parameter datatypes to be declared as allowing NULL
or NOT NULL
. This was introduced for Hekaton (memory optimised tables).
虽然在存储过程的 Transact-SQL 语法"中没有记录为支持语法,但它看起来允许 NULL
但在 NOT NULL
和抛出错误.
Though it isn't documented as supported for the grammar in "Transact-SQL Syntax for Stored Procedures" it looks like it allows NULL
but balks at NOT NULL
and throws an error.
参数 '@MyArgument' 已声明为 NOT NULL.非空参数只支持本地编译的模块,除了用于内联表值函数.
The parameter '@MyArgument' has been declared as NOT NULL. NOT NULL parameters are only supported with natively compiled modules, except for inline table-valued functions.
显式指定 NULL
没有任何价值 - 这是默认且唯一的选项.常规存储过程没有声明性语法来指示参数必须NOT NULL
.
There is no value in specifying NULL
explicitly - this is the default and only option. There is no declarative syntax for regular stored procs to indicate that parameters must be NOT NULL
.
这篇关于存储过程参数“NULL"或“= NULL"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:存储过程参数“NULL"或“= NULL"


- 如何使用 pip 安装 Python MySQLdb 模块? 2021-01-01
- 以一个值为轴心,但将一行上的数据按另一行分组? 2022-01-01
- 如何将 SonarQube 6.7 从 MySQL 迁移到 postgresql 2022-01-01
- 远程 mySQL 连接抛出“无法使用旧的不安全身份验证连接到 MySQL 4.1+"来自 XAMPP 的错误 2022-01-01
- 如何将 Byte[] 插入 SQL Server VARBINARY 列 2021-01-01
- 更改自动增量起始编号? 2021-01-01
- SQL 临时表问题 2022-01-01
- 导入具有可变标题的 Excel 文件 2021-01-01
- 在SQL中,如何为每个组选择前2行 2021-01-01
- 使用 Oracle PL/SQL developer 生成测试数据 2021-01-01