SQL Server Custom Custom Data Type with Default Returns Null

I would like to know why when I create a custom data type in SQL Server based on a non-zero integer and assign it a default value, I cannot get this value if it is not a table definition (only one declared variable ) Here is my code:

BEGIN TRAN; GO CREATE TYPE Province FROM INT NOT NULL; GO CREATE DEFAULT ProvinceDefault AS 4; GO EXEC sp_bindefault 'ProvinceDefault', 'Province'; GO DECLARE @Province Province; SELECT @Province; GO ROLLBACK TRAN; 

It returns NULL

+5
source share
1 answer

MSDN: -

[@objname =] 'object_name'

It is the name of the table and column, or the data type of the alias to which you want to bind the default value. object_name is nvarchar (776) with no default value. object_name cannot be defined using varchar (max), nvarchar (max), varbinary (max), xml or CLR user-defined types .

Link: https://msdn.microsoft.com/en-us/library/ms177503.aspx

0
source

Source: https://habr.com/ru/post/1264341/


All Articles