I did a little test, created a table with a column that had a default value but did not allow null.
Then this is an SQL expression:
INSERT INTO [Test].[dbo].[Table_1] ([TestText]) VALUES (null)
Gives this error:
Msg 515, Level 16, State 2, Line 1
Cannot insert a NULL value in the column "TestText", table 'Test.dbo.Table_1'; column does not allow zeros. INSERT does not work.
The problem is that the insert indicates all columns, as well as those that have default values. Insert tries to update columns with null values.
You have 2 options:
- Refresh a table through a view that does not contain default columns
- Set default values ββin C # code
The default is business logic, so there is a case where it is set at the business level of your application.
Shiraz bhaiji
source share