Friday, February 22, 2019

SQL Not NULL Constraint

SQL Not NULL constraint ensures the columns cannot have NULL value and if you insert or update NULL value to this column, it throws exception

Cannot insert the value NULL into column 'StatusCode', table 'dbo.OrderStatus'; column does not allow nulls. INSERT fails.

Syntax: Create NOT NULL constraint on Create Table

The below SQL will create a NOT NULL constraint on StatusCode Column

Create Table OrderStatus


       StatusID int IDENTITY(1,1) NOT NULL,

       StatusCode varchar(3) NOT NULL,

       StatusDescription varchar(50),



No comments:

SQL Server - Identify unused indexes

 In this blog, we learn about the index usage information (SYS.DM_DB_INDEX_USAGE_STATS) and analyze the index usage data (USER_SEEKS, USER_S...