What is NOT NULL Constraint in SQL Server?
Introduction:
In this article i will explain what is NOT NULL Constraint in SQL Server.
Description:
In previous articles i explained what is Constraint. And how many Constraints available in SQL Server. Now i will explain what is NOT NULL Constraint in SQL Server.
NOT NULL Constraint:
NOT NULL specifies that the column does not accept NULL values.
Example:
Create table Employee
(
EmpNo int not null,
EmpName varchar(50) not null
)
Employee table is created.
Insert data into Employee table.
insert into Employee values(1, 'AAA')
(1 row(s) affected)
1 row inserted into Employee table.
insert into Employee(EmpNo) values(2)
After executing the above statement we got the following error. Because EmpName column does not allow null value.
Cannot insert the value NULL into column 'EmpName', table 'Test.dbo.Employee'; column does not allow nulls. INSERT fails.
-
CreatedOct 18, 2013
-
UpdatedOct 03, 2020
-
Views2,007
Related Articles
Different types of variables in SQL Server
What is Cross Join in SQL Server
How delete record from parent table when there is Foreign Key relation in SQL Server
What is the differences between CHAR, NCHAR, VARCHAR and NVARCHAR in SQL Server?
How to add or remove a column from a table in SQL Server?
How to insert values into Identity Column in SQL Server?
How to get a fixed-length value in SQL Server?
What is Left Join (or) Left Outer Join in SQL Server?
How to get current week dates in SQL Server?
What are the different types of Date formats in SQL Server?