Sunday 15 February 2015

sql - Does NULL have a data type? -


I went to the same code as today.

  Select Audit daemon, ObjectID, Audit subdomain =   

It looks like the data type information can be linked to an empty value. Does it attach metadata to the NULL value that identifies as a specific data type?

Tells a way to detect data types in SQL Server, but when I try the following line, it comes back as a tap:

  Vastar (20)) as cast cast (SQL_VARIANT_PROPERTY (convert (INT, NULL, 'bassette'))    

In SQL Server, NULL one INT by default, in all the scenarios I can think you can define it with the following code:

  SELECT x = NULL INTO #x; EXEC tempdb..sp_columns '#x';   

Result: TABLE_QUALIFIER TABLE_OWNER TABLE_NAME COLUMN_NAME DATA_TYPE TYPE_NAME --------------- ------ ----- ---------- ----------- --------- --------- tempdb dbo #x___ .. X 4 int

Before you put it in a table or affiliate with a relevant metadata, what should you buy from it? Does this difference that it is INT or DATETIME or something else? What will you do with that information?

returns SQL_VARIANT_PROPERTY return NULL because this metadata and require a value for both to be meaningful (see it Use only one different type to mix):

  SELECT SQL_VARIANT_PROPERTY (NULL, 'BaseType'); DECLARE @ x ​​DATE; SELECT SQL_VARIANT_PROPERTY (@x, 'BaseType'); DECLARE @ y DATE = SYSDATETIME (); SELECT SQL_VARIANT_PROPERTY (@y, 'BaseType');   

Result:

  NULL NULL date   

So it requires both types and A value to accurately determine the base type.

Why this works in the same way, shrug You have to ask people with source code access.

Note that the NULL needs to be adopted only when you have compelled the hand of SQL Server: you have created a table based on it very well The case may be that the SQL server will return an error in this situation (and in fact in many cases where you think the data type means). The way to avoid this is not to create situations where SQL Server has to guess (which is why I asked, what would you do with this information?).

No comments:

Post a Comment