Thursday 7 November 2019

Altering a column: null to not null in SQL

In this article, I am explaining how to altering a column null to not null in Sql Server.

Query:-


First make all current NULL values disappear from that column

UPDATE [Table] SET [Column] = '' WHERE [Column] IS NULL

Then, update the column of table to disallow NULLs

ALTER TABLE [Table] ALTER COLUMN [Column] varchar(50) NOT NULL