Sql-server – Default constraint issue

constraintddldefault valuesql server

I have a table TempTable with one column having a default constraint

ALTER TABLE [dbo].[TempTable] 
ADD  CONSTRAINT [DF_TempTable_Version]  
DEFAULT ((1)) FOR [Version]

Version is defined as decimal (18,1)

Most of the time the value 1.00 is inserted into the column but in some cases its inserting a null value.

How we can identify if the constraint is failing or if there is some other issues causing this?

Best Answer

How we can identify if the constraint is failing or if there is some other issues causing this?

The most likely cause is that a client is simply inserting a null, or updating the column to null, neither of which is prevented by a default constraint.

If you don't want nulls, just declare the Version column as NOT NULL, or add a check constraint.