How to Alter a Column from Null to Not Null in SQL Server?
With this article, we will learn how to alter a column from accepting Null values to Not Null in SQL Server. The prerequisites of this article are you should be having a MSSQL server on your computer.
What is a query?
A query is a statement or a group of statements written to perform a specific task, like retrieve data, save data into a database.
Attention reader! Don’t stop learning now. Learn SQL for interviews using SQL Course by GeeksforGeeks.
So, we will create a database first:
Step 1: Creating Database
CREATE DATABASE GFG
Step 2: Using database
Step 3: Create a table with a null column
CREATE TABLE gfgTutorial( id integer, Name varchar(20) )
Describe the table
Step 4: Change the id column to not null
ALTER TABLE gfgTutorial ALTER COLUMN id VARCHAR (50) NOT NULL;
So now our table id column is changed to not null
So we have successfully changed the id column to not null in the gfgTutorial table.