Skip to content
Related Articles

Related Articles

Save Article
Improve Article
Save Article
Like Article

How to Alter a Column from Null to Not Null in SQL Server?

  • Last Updated : 23 Sep, 2021

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

USE GFG

Step 3: Create a table with a null column

CREATE TABLE gfgTutorial(
id integer,
Name varchar(20)
)

Describe the table

sp_help 'dbo.gfgTutorial'

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

Changed null id to not null

So we have successfully changed the id column to not null in the gfgTutorial table.

My Personal Notes arrow_drop_up
Recommended Articles
Page :