How to restrict NULL as parameter to stored procedure SQL Server?

前端 未结 5 1539
孤独总比滥情好
孤独总比滥情好 2020-12-09 14:52

Is it possible to create a stored procedure as

CREATE PROCEDURE Dummy 
    @ID INT NOT NULL
AS
BEGIN
END

Why is it not possible to do somet

5条回答
  •  情话喂你
    2020-12-09 15:35

    You could check for its NULL-ness in the sproc and RAISERROR to report the state back to the calling location.

    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
    

    Then call:

    exec dbo.CheckForNull @i = 1 
    

    or

    exec dbo.CheckForNull @i = null 
    

提交回复
热议问题