SQL Server: NOT NULL Constraint

 SQL Server     sbo     Updated on Oct 18, 2013     VIKRAM     518   

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.

  Related Articles
Java Script: Create/Insert rows dynamically to HTML Table and Remove/Delete rows from HTML Table
Java Script: Create HTML Table dynamically
SQL Server: Delete record from parent table when there is Foreign Key relation between parent and child tables
SQL Server: DEFAULT Constraint
SQL Server: FOREIGN KEY Constraint
SQL Server: PRIMARY KEY Constraint
SQL Server: UNIQUE Constraint
SQL Server: CHECK Constraint
SQL Server: Constraints
SQL Server: Temporary Table
  Recent Articles
Java Script: Create/Insert rows dynamically to HTML Table and Remove/Delete rows from HTML Table
Java Script: Create HTML Table dynamically
SQL Server: Delete record from parent table when there is Foreign Key relation between parent and child tables
SQL Server: DEFAULT Constraint
SQL Server: FOREIGN KEY Constraint
SQL Server: PRIMARY KEY Constraint
SQL Server: UNIQUE Constraint
SQL Server: CHECK Constraint
SQL Server: Constraints
SQL Server: Temporary Table