开发者

Why is DEFAULT Keyword Allowed in CREATE PROCEDURE Command

开发者 https://www.devze.com 2023-02-07 15:30 出处:网络
In t开发者_如何学Pythonhe following statement, the DEFAULT keyword appears where a default value is defined for a parameter.

In t开发者_如何学Pythonhe following statement, the DEFAULT keyword appears where a default value is defined for a parameter.

CREATE PROCEDURE usp_Test
    @sp_param1 varchar(20) = DEFAULT
AS
    SELECT @sp_param1 AS myTest
;

NULL is assigned to @sp_param1. But, The default value must be a constant or the NULL keyword.

Why is the DEFAULT keyword allowed in this situation?


The DEFAULT keyword is a placeholder for something that you want to provide, but is not really even NULL. Most commonly seen in

exec SProcName 2, DEFAULT

Even though the 2nd param is supplied, it is not actually a value, but is an instruction to use the DEFAULT value of the 2nd param.

When used in the CREATE PROC itself, it parses, but is simply treated as NULL.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号