Basic Logics · Real Scenario Logic's

To know the Default Datatype of NULL and Empty in SQL Server

Introduction

In this Blog post, we are going to see what is the default datatype of NULL and Empty and how to know it in SQL Server.

How to know the Default Datatype

To know the Default Datatype, one of the simple method we can use is, to add the alias name and move it to the temporary table and view its structure.

Please check here, for Viewing the Structure of Temp Table.

To know the Default Datatype of NULL

SQL Script

SELECT NULL AS Default_Datatype INTO #TestTable;
--	SELECT Default_Datatype FROM #TestTable;
EXEC TEMPDB..SP_HELP #TestTable;
DROP TABLE #TestTable;

Image Pic

Default Datatype of NULL

Note-

The Default Datatype of NULL is INT and it is suitable only when it is being created as a Table. Apart from that, it is always Non-typed.

To know the Default Datatype of Empty

SQL Script

SELECT '' AS Default_Datatype INTO #TestTable;
--	SELECT Default_Datatype FROM #TestTable;
EXEC TEMPDB..SP_HELP #TestTable;
DROP TABLE #TestTable;

Image Pic

Default Datatype of Empty

The Default Datatype of Empty is VARCHAR(1).

Conclusion

Thus, we saw how to know the Default Datatype and what is the default Datatype of NULL and Empty in SQL Server.

Thanks for reading and Follow Blog and Show your Support for many more interesting upcoming Posts!

Advertisement

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s