sql-not-null-constraint

Get Started: SQL NOT NULL Constraint

In This Article, You Will Know About SQL NOT NULL Constraint. 

Before moving ahead, let’s know a bit about the SQL ALTER TABLE Statement.

Table of Contents

SQL NOT NULL Constraint

In SQL, a table can have a null value by default but NOT NULL Constraint stops taking any null value in the table.

It always enforces a field to contain a value, which means it doesn’t allow you to insert or update a value without adding any value to the field.

SQL NOT NULL on CREATE TABLE

Example: Use NOT NULL statements not to accept any null value.

NOT NULL statements will make sure that Columns “Name”, “Class”,  and “Roll_No” will not have any empty field or null value when the table is created called “Student_Info”.

				
					CREATE TABLE Student_Info
	Name char(10) NOT NULL,
	Class char(8) NOT NULL,
	Roll_No int NOT NULL,
	Section char(1)
);
				
			

SQL NOT NULL on ALTER TABLE

Example: Use NOT NULL statements not to accept any null value.

When the table is already created, use the NOT NULL statement on column “Section”to make sure not to have any null value.

				
					CREATE TABLE Student_Info
MODIFY Section char(1) NOT NULL;
				
			

If you find anything incorrect in the above-discussed topic and have further questions, please comment below.

Connect on:

Recent Post

Popular Post

Top Articles

Archives
Categories

Share on