gpt4 book ai didi

sql - 如何限制 NULL 作为 SQL Server 存储过程的参数?

转载 作者:行者123 更新时间:2023-12-01 18:45:06 25 4
gpt4 key购买 nike

是否可以创建一个存储过程

CREATE PROCEDURE Dummy 
@ID INT NOT NULL
AS
BEGIN
END

为什么不能做这样的事情?

最佳答案

您可以检查存储过程中的 NULL 性,并使用 RAISERROR 将状态报告回调用位置。

CREATE   proc dbo.CheckForNull @i int 
as
begin
if @i is null
raiserror('The value for @i should not be null', 15, 1) -- with log

end
GO

然后调用:

exec dbo.CheckForNull @i = 1 

exec dbo.CheckForNull @i = null 

关于sql - 如何限制 NULL 作为 SQL Server 存储过程的参数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/330303/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com