How to input the value 'NULL' into nvarchar column in SQL Server?

10,738

Solution 1

Note the quotes:

INSERT INTO yourtable (varcharfield) VALUES ('NULL'); // string null
INSERT INTO yourtable (varcharfield) VALUES (NULL); // actual null

Solution 2

If set the default in code instead of the designer is should work.

ALTER TABLE [myTable] ADD  DEFAULT ('NULL') FOR [TextColumn]
Share:
10,738
VKarthik
Author by

VKarthik

Updated on June 09, 2022

Comments

  • VKarthik
    VKarthik about 2 years

    I have a requirement to insert the literal value 'NULL' into a nvarchar column as a default value. But when I insert records the default is going as db NULL instead of the literal 'NULL'. Can someone tell me where I am going wrong?