Casting and Conversion

Learn about casting and converting a value to a different data type in T-SQL.

When we assign a value of one type to a column that stores data of another type, MS SQL Server tries to perform a conversion and cast the value to the needed type. Let’s consider a table with one column of type NVARCHAR:

CREATE TABLE ReferenceTable
(
    Data NVARCHAR(100)
);

If we try to insert a numeric value into the column above, an automatic conversion to NVARCHAR takes place:

Get hands-on with 1200+ tech skills courses.