Skip to Content

How user defined data type treat the null values

Dec 24, 2017 at 07:26 PM


avatar image

According to the documentation. using sp_addtype, we specifying null type The null type determines how the user-defined datatype treats nulls. You can create a user-defined datatype with a null type of “null”, “NULL”, “nonull”, “NONULL”, “not null”, or “NOT NULL”.

However, It seems NONULL or NOT NULL provided in the type definition will not prevent the type from accepting the null value. Any idea?

My test is like the following. There is no error raised when assign, the new type variable can have NULL value assigned to it.

Thank you very much.

ASE 16

1> sp_addtype nm , "varchar(20)", "NONULL"

2> go Type added.

(return status = 0)

1> declare @ss nm

2> select @ss = null

3> go

(1 row affected)

1> declare @ss nm

2> select @ss = null

3> select isnull(@ss,"NULLVAL")

4> go

(1 row affected)


NULLVAL (1 row affected)

10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

0 Answers